#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define ll __int64
#define inf 0x3f3f3f3f
#define N 1001000
char ch[20];
ll dp[1<<18][110];
int c[20],v[20];
int main()
{
int i,j,k,l,m;
cin>>ch>>m;
int len=strlen(ch);
for(i=0;i<len;i++)
c[i]=ch[i]-'0';
int cnt=(1<<len);
dp[0][0]=1;
for(i=0;i<cnt;i++)
{
for(j=0;j<m;j++)
{
memset(v,0,sizeof(v));
for(k=0;k<len;k++)
{
if(i==0 && c[k]==0) continue;
if(v[c[k]]) continue;
if((i>>k)&1) continue;
dp[i+(1<<k)][(j*10+c[k])%m]+=dp[i][j];
v[c[k]]=1;
}
}
}
cout<<dp[cnt-1][0]<<endl;
//system("pause");
}
Codeforces Round #235 (Div. 2) ----D. Roman and Numbers
最新推荐文章于 2020-05-10 15:02:00 发布