Cod sursa(job #1439576)
Utilizator | Data | 22 mai 2015 18:15:47 | |
---|---|---|---|
Problema | Ratphu | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Teme Pregatire ACM Unibuc 2014, Anul I, Semestrul 2 | Marime | 0.6 kb |
#include<fstream>
using namespace std;
ifstream f("ratphu.in");
ofstream g("ratphu.out");
#define MAXN 1 << 18
#define ll long long
ll int N, M[ MAXN ][23];
int P, v[23], e, confmax, conf, j, r;
int main()
{
f >> N >> P;
for (;N;N /= 10){
v[e] = N % 10;
++M[(1 << e)][v[e++] % P];
}
confmax = (1 << e);
for(conf = 1; conf < confmax; ++conf)
for(j = 0; j < e; ++j)
if(!((1 << j) & conf))
for(r = 0; r < P; ++r)
M[conf | (1 << j)][(r * 10 + v[j]) % P] += M[conf][r];
g << M[confmax - 1][0];
}