Cod sursa(job #1706621)
| Utilizator | Data | 22 mai 2016 21:47:59 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <bits/stdc++.h>
using namespace std;
int c[20],p,s,i,j,mask;
long long n,dp[1<<18][20];
int main()
{
freopen("ratphu.in","r",stdin);
freopen("ratphu.out","w",stdout);
scanf("%lld %lld",&n,&p);
while(n)
c[s++]=n%10,n/=10;
reverse(c,c+s);
dp[0][0]=1;
for(mask=0;mask<(1<<s);mask++)
for(i=0;i<p;i++)
if(dp[mask][i])
for(j=0;j<s;j++)
if(!(mask&(1<<j)))
dp[mask|(1<<j)][(10*i+c[j])%p]+=dp[mask][i];
printf("%lld",dp[(1<<s)-1][0]);
return 0;
}
