Cod sursa(job #741229)
| Utilizator | Data | 25 aprilie 2012 18:26:40 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include<stdio.h>
#include<string.h>
char x[20];
int c[20],dp[264000][25];
int main()
{
freopen("ratphu.in","r",stdin);
freopen("ratphu.out","w",stdout);
long i,j,k,lim,p,n,conf,R;
scanf("%s",x);
scanf("%d",&p);
n=strlen(x);
dp[0][0]=1;
for(i=0;i<n;i++)
c[i+1]=x[i];
lim=(1<<n)-1;
for(i=0;i<=lim;i++)
for(j=0;j<p;j++)
if(dp[i][j]!=0)
for(k=0;k<n;k++)
if(!(i&(1<<k)))
{
conf=i|(1<<k);
R=(j*10+c[k+1])%p;
dp[conf][R]+=dp[i][j];
}
printf("%ld\n",dp[lim][0]);
return 0;
}
