Cod sursa(job #3153859)
Utilizator | sui merchant suimerchant | Data | 1 octombrie 2023 17:12:29 |
---|---|---|---|
Problema | Ratphu | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.46 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fin("ratphu.in");
ofstream fout("ratphu.out");
int p;
int dp[1<<18][21];
char s[20];
int main()
{
fin>>(s)>>p;
int n=strlen(s);
dp[0][0]=1;
for(int stare=0;stare<(1<<n);stare++)
for(int k=0;k<p;k++)
for(int i=0;i<n;i++)
if(!(stare&(1<<i))) dp[stare | (1<<i)][(k*10+s[i]-'0')%p]+=dp[stare][k];
fout<<dp[(1<<n)-1][0];
return 0;
}