sql數(shù)據(jù)庫環(huán)境網(wǎng)站搭建教程百度總部公司地址在哪里
題目描述
題目分析?
此題目的最終目標(biāo)是將字母都填上數(shù)使等式符合條件,實際我們發(fā)現(xiàn)可以使用搜索將所有符合條件的進(jìn)行判斷(答案:29)
由于小數(shù)可能會出現(xiàn)錯誤故我們將其進(jìn)行簡單變化進(jìn)行搜索
#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;
}