Cod sursa(job #2738232)
Utilizator | Taga Stefan stefantaga | Data | 5 aprilie 2021 16:38:54 |
---|---|---|---|
Problema | Ratphu | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.81 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
long long n,p,cop,nr[25],q,lim,bit,j,i,rest[1010];
long long din[(1<<19)][21];
int main()
{
f>>n>>p;
cop=n;
while (cop)
{
nr[++q]=cop%10;
cop=cop/10;
}
lim=(1<<q);
din[0][0]=1;
for (i=1;i<=1005;i++)
{
rest[i]=i%p;
}
for (i=0;i<lim;i++)
{
for (j=0;j<p;j++)
{
if (din[i][j]>0)
{
for (bit=0;bit<q;bit++)
{
if ((i&(1<<bit))==0)
{
din[i^(1<<bit)][rest[j*10+nr[bit+1]]]+=din[i][j];
}
}
}
}
}
g<<din[lim-1][0];
return 0;
}