AcWing 1209. 带分数
原题链接
简单
作者:
yuan1234
,
2021-04-04 09:23:45
,
所有人可见
,
阅读 252
#include <bits/stdc++.h>
using namespace std;
int n, vis[15],cop[15],ans;
bool check(int a,int c)
{
long long b = (long long) c *n - a * c;
if(a==0||b==0||c==0)
return false;
memcpy(cop,vis,sizeof(vis));
while(b)
{
int x=b%10;
if(x==0||cop[x]==1)
return false;
cop[x]=1;
b/=10;
}
for(int i=1;i<=9;i++)
{
if(cop[i]==0)
return false;
}
return true;
}
void dfsc(int step, int a, int c)
{
if (step >= 9)
return;
if(check(a,c))
ans++;
for(int i=1;i<=9;i++)
{
if(vis[i]==0)
{
vis[i]=1;
dfsc(step+1,a,c*10+i);
vis[i]=0;
}
}
}
void dfsa(int step, int a)
{
if (a >= n)
return;
if (a)
dfsc(step + 1, a, 0);
for (int i = 1; i <= 9; i++)
{
if (!vis[i])
{
vis[i] = 1;
dfsa(step + 1, a * 10 + i);
vis[i] = 0;
}
}
}
int main()
{
cin >> n;
dfsa(0,0);
cout<<ans<<endl;
system("pause");
return 0;
}