Cod sursa(job #466872)
Utilizator | Florin Chirica elfus | Data | 27 iunie 2010 20:19:40 |
---|---|---|---|
Problema | Ratphu | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.52 kb |
//dinamica pe bitzisori
#include<stdio.h>
#define LL long long
LL elfus[1<<20][20];
int cifre[30];
int main()
{
LL N;
int p,i,j,k,val=0;
freopen("ratphu.in","r",stdin);
freopen("ratphu.out","w",stdout);
scanf("%lld%d",&N,&p);
do
{
cifre[val++]=N%10;
N/=10;
}
while(N);
elfus[0][0]=1;
for(i=0;i< (1<<val) ; i++)
for(j=0;j<p;j++)
if(elfus[i][j])
for(k=0;k<val;k++)
if(!(1<<k)&i)
elfus[i+(1<<k)][(j*10+cifre[k])%p]+=elfus[i][j];
printf("%lld",elfus[(1<<val)-1 ][0]);
return 0;
}