AcWing 1209. 带分数
原题链接
简单
作者:
小小bug
,
2022-05-01 14:50:53
,
所有人可见
,
阅读 155
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n;
int nums[N];
bool st[N];
int cnt;
int cacl(int l, int r)
{
int res = 0;
for(int i = l; i <= r; i++)
{
res = res * 10 + nums[i];
}
return res;
}
void dfs(int u)
{
if(u > 9)
{
for(int i = 1; i <= 6; i++)
{
for(int j = i + 1; j < 9; j++)
{
int a = cacl(1,i);
int b = cacl(i+1,j);
int c = cacl(j+1,9);
if(n * c == a * c + b) cnt ++;
}
}
return;
}
for(int i = 1; i <= 9; i++)
{
if(!st[i])
{
st[i] = true;
nums[u] = i;
dfs(u + 1);
st[i] = false;
}
}
}
int main()
{
cin >> n;
dfs(1);
cout << cnt << endl;
return 0;
}