[ZJ]a524: 手機之謎
題目:
http://zerojudge.tw/ShowProblem?problemid=a524
--------------------------------------------------------------------------------------------------------------
#include<cstdio>
#include<cstring>
int a[10]={0},b[10]={0},n;
void dfs(int x)
{
int i;
if(x==n){
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("\n");
return;
}
for(i=n;i>=1;i--){
if(b[i]==0){
b[i]=1;
a[x]=i;
dfs(x+1);
b[i]=0;
}
}
}
int main()
{
while(scanf("%d",&n) == 1)
{
memset(b,0,sizeof(b));
dfs(0);
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=a524
--------------------------------------------------------------------------------------------------------------
#include<cstdio>
#include<cstring>
int a[10]={0},b[10]={0},n;
void dfs(int x)
{
int i;
if(x==n){
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("\n");
return;
}
for(i=n;i>=1;i--){
if(b[i]==0){
b[i]=1;
a[x]=i;
dfs(x+1);
b[i]=0;
}
}
}
int main()
{
while(scanf("%d",&n) == 1)
{
memset(b,0,sizeof(b));
dfs(0);
}
return 0;
}
留言
張貼留言