Mai intai trebuie sa te autentifici.
Cod sursa(job #471228)
| Utilizator | Data | 17 iulie 2010 20:28:26 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.45 kb |
#include<algorithm>
using namespace std;
#define DIM 20
int n,p;
long long b[1<<DIM][DIM];
char s[DIM];
int main ()
{
freopen("ratphu.in","r",stdin);
freopen("ratphu.out","w",stdout);
int i,j,q;
scanf("%s %d",&s,&p);
n=strlen(s);
b[0][0]=1;
for(i=0;i<(1<<n);++i)
for(j=0;j<p;++j)
if(b[i][j])
for(q=0;q<n;++q)
if(!(i&(1<<q)))
b[i|(1<<q)][(j*10+s[q]-'0')%p]+=b[i][j];
printf("%lld",b[(1<<n)-1][0]);
return 0;
}