Cod sursa(job #1433895)
| Utilizator | Data | 10 mai 2015 09:15:46 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include<fstream>
#include<cstring>
using namespace std;
long long dp[270000][20],c[20],r,k,i,j,p,n,l,x;
char s[20];
int main ()
{
ifstream f("ratphu.in");
ofstream g("ratphu.out");
f>>s;
for (i=0;i<strlen(s);++i)
c[i+1]=s[i]-'0';
f>>p;
n=strlen(s);
l=(1u<<n)-1;
dp[0][0]=1;
for (i=0;i<=l;++i)
for (j=0;j<p;++j)
if (dp[i][j])
for (k=0;k<n;++k)
if (!(i&(1u<<k))) {
x=i|(1u<<k);
r=j*10+c[k+1];
while (r>=p) r-=p;
dp[x][r]+=dp[i][j];
}
g<<dp[l][0];
f.close();
g.close();
return 0;
}
