Mai intai trebuie sa te autentifici.
Cod sursa(job #2220005)
Utilizator | Data | 10 iulie 2018 12:45:36 | |
---|---|---|---|
Problema | Ratphu | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.66 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ratphu.in");
ofstream fout("ratphu.out");
const int nmax=(1<<19);
int n,p;
int dp[nmax][20],a[20];
char s[20];
int main()
{
fin>>s;
fin>>p;
n=strlen(s);
for(int i=0;s[i];i++)
a[i]=s[i]-'0';
const int Nmax=(1<<n);
dp[0][0]=1;
for(int stare=0;stare<Nmax;stare++)
for(int bit=0;bit<n;bit++)
if(!(stare & (1<<bit)))
for(int rest=0;rest<p;rest++)
dp[stare | (1<<bit)][(rest*10+a[bit])%p]+=dp[stare][rest];
fout<<dp[Nmax-1][0]<<"\n";
fin.close();
fout.close();
return 0;
}