题目描述


题目分析
此题目的最终目标是将字母都填上数使等式符合条件,实际我们发现可以使用搜索将所有符合条件的进行判断(答案:29)

由于小数可能会出现错误故我们将其进行简单变化进行搜索
cpp
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int x[N], ans;
bool v[N];
bool check(int x[])
{
int a = x[1];
int b = x[2];
int c = x[3];
int d = x[4] * 100 + x[5] * 10 + x[6];
int e = x[7] * 100 + x[8] * 10 + x[9];
if(a * c * e + b * e + c * d == 10 * c * e)return true;
return false;
}
void dfs(int num)
{
if(num > 9)
{
if(check(x))ans ++;
return;
}
for(int i = 1; i <= 9; i ++)
{
if(!v[i])
{
v[i] = true;
x[num] = i;
dfs(num + 1);
v[i] = false;
}
}
}
int main()
{
for(int i = 1; i <= 9; i ++)x[i] = i;
dfs(1);
cout << ans;
return 0;
}