补全等式
题目要求下图中,每个方块代表
1…13中的某一个数字,但不重复。
例如:1×2+9×7=13×5
10×8−12*3=11×4
只要有任意一个方块代表的数字不同,就算两种不同的方案。
请你计算,一共有多少种不同的方案。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/26d9cae6067eaecd9789ab7f8dda1c38.jpeg)
#include<iostream>
#include<string.h>
using namespace std;
int a[12] = { 0 };
int Count=0;
bool visit[14] = { false };
void dfs(int depth)
{
if (depth == 6 && a[0] * a[1] + a[2] * a[3] != a[4] * a[5])
return;
if (depth == 12)
{
if (a[6] * a[7] + a[8] * a[9] != a[10] * a[11])
{
Count++;
return;
}
}
for (int i = 1; i <= 13; i++)
{
if (!visit[i])
{
visit[i] = true;
a[depth] = i;
dfs(depth + 1);
a[depth] = 0;
visit[i]= false;
}
}
}
int main()
{
dfs(0);
cout << Count;
return 0;
}
}