Cod sursa(job #1439344)

Utilizator emiiMihailescu Ionut Emanuel emii Data 22 mai 2015 10:30:25
Problema Ratphu Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include<iostream>
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
long long d[1<<19][21];
int main()
{int x,p;
f>>x>>p;
int nr=0,cif[20];
while(x)
    cif[nr++]=x%10,x/=10;
d[0][0]=1;x=1<<nr;
for(int i=0;i<x;i++)
    for(int j=0;j<p;j++)
        if(d[i][j]!=0)
        for(int k=0;k<nr;k++)
            {
                if((1<<k&i)==0)
            {
            int t=j*10+cif[k];
            while(t>=p)
                t-=p;
            d[i|1<<k][t]=d[i][j]+d[i|1<<k][t];
            }
            }
g<<d[x-1][0];
return 0;
}