小学奥数

版权声明:小简原创 https://blog.csdn.net/qq_43469554/article/details/85062377
#include<stdio.h>
int a[10];
int book[10];
int total = 0;
void DFS(int step)
{
	int i;
	if (step == 10&&a[1] * 100 + a[2] * 10 + a[3] + a[4] * 100 + a[5] * 10 + a[6] == a[7] * 100 + a[8] * 10 + a[9])
	{
		total++;
		for (i=1; i<=9; i++)
		{
			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[step] = i;
			book[i] = 1;
			DFS(step + 1);
			book[i] = 0;
		}
	}
}
int main()
{
	DFS(1);
	printf("total = %d", total/2);
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/qq_43469554/article/details/85062377