hdu 1027 Ignatius and the Princess II

http://acm.hdu.edu.cn/showproblem.php?pid=1027

用递归必然超时,所以我用的STL。

可以用STL里面的net_permutation来做。

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int N, M;
	while(cin>>N>>M){
		int a[1010];
		for(int i=0;i<N;i++)
			a[i]=i+1;
		while(--M){
			next_permutation(a,a+N);
		}
		for(int i=0;i<N;i++){
			if(i!=0)
				cout<<" ";
			cout<<a[i];
		}
		cout<<endl;	
	}
	return 0;
}


你可能感兴趣的:(hdu 1027 Ignatius and the Princess II)