(n个数选r个全排列)

https://acm.nyist.net/JudgeOnline/problem.php?pid=32

输出结果中 不能重复使用(若有543 则不能有345,435等)


/***************************
# 2013-8-22 15:46:46 
# Time: 8MS   Memory: 232KB
# Author: zyh
# Status: Accepted
***************************/ 

#include<stdio.h>
#include<string.h>
int r,n;
bool vis[12];
int s[12];
void permutation(int t)
{
	int i;
	if(t>r){
		for(i=1;i<=r;i++) printf("%d",s[i]);
		puts("");	
		return;
	} 
	for(i=n;i>0;i--){
		if(!vis[i] && i<s[t-1] ){ //按题意 加上 i<s[t-1] 限制 
			s[t] = i;
			vis[i] = 1;
			permutation(t+1); 
			vis[i] = 0;
		}
	}
}
int main()
{
	while(~scanf("%d%d",&n,&r))
	{
		memset(vis,0,sizeof(vis));
		memset(v,0,sizeof(v));
		s[0] = 111;
		permutation(1);
	}
	return 0;
}