Cod sursa(job #1443226)
| Utilizator | Data | 27 mai 2015 11:15:25 | |
|---|---|---|---|
| Problema | Ratphu | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Teme Pregatire ACM Unibuc 2014, Anul I, Semestrul 2 | Marime | 0.67 kb |
#include <fstream>
#define nx 1000000
using namespace std;
int n, p;
char c[30];
long long sol[nx][30];
ifstream fin("ratphu.in");
ofstream fout("ratphu.out");
int main()
{
fin >> c >> p;
for (; '0' <= c[n] && c[n] <= '9'; n++)
{
c[n] -= '0';
}
sol[0][0] = 1;
for (int i = 0; i < (1<<n); i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < p; k++)
{
if ((i&(1<<j)) == 0)
{
sol[i+(1<<j)][(k*10+c[j])%p] += sol[i][k];
}
}
}
}
fout << sol[(1<<n)-1][0];
return 0;
}
