Cod sursa(job #1473127)
| Utilizator | Data | 18 august 2015 16:49:09 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <fstream>
using namespace std;
ifstream f("ratphu.in"); ofstream g("ratphu.out");
long long n,dp[1<<18][20];// numarul de posibilitati luand configuratia 'i', sa am restul 0
int cif[20];
int main()
{ int p,i,j,k,q=0;
f>>n>>p;
while(n) {cif[q++]=n%10; n/=10;}
for(k=0;k<q;++k) dp[1<<k][cif[k]%p]=1;
for(i=1;i<(1<<q);++i)
for(j=0;j<q;++j)
if((i&(1<<j))==0)
for(k=0;k<p;++k)
dp[i|(1<<j)][(k*10+cif[j])%p]+=dp[i][k];
g<<dp[(1<<q)-1][0]; g.close(); return 0;
}
