题目:
代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//a[9] 十二个盒子的值
//book[9] 十二个扑克牌的情况(1-9)
//a[step] 第step个盒子
//
int book[10],a[10],n,total=0;
void dfs(int step )
{
int i;
if(step==9+1)
{
if(a[1]*100+a[2]*10+a[3]*1+a[4]*100+a[5]*10+a[6]*1==a[7]*100+a[8]*10+a[9])
{
total++;
printf("%d%d%d+%d%d%d=%d%d%d\n",a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]);
}
}
for(i=1;i<=9;i++)
{
if(book[i]==0)
{
a[i]=i;
book[i]=1;
dfs(step+1);
book[i]=0;
}
}
return;
}
int main()
{
dfs(1);
printf("有%d个",total);
system("pause");
return 0;
}