标签:sizeof get scan www www. nbsp com \n return
[题目链接]
https://www.lydsy.com/JudgeOnline/problem.php?id=1072
[算法]
状压DP
[代码]
#include<bits/stdc++.h> using namespace std; #define MAXD 1000 const int MAXS = 2048; int i,j,k,T,len,d,MASK; char s[20]; long long f[MAXS][MAXD]; long long ans; long long fac[15]; int cnt[10]; int main() { fac[0] = 1; for (i = 1; i <= 10; i++) fac[i] = fac[i-1] * i; scanf("%d",&T); while (T--) { scanf("%s%d",&s,&d); len = strlen(s); MASK = (1 << len) - 1; memset(f,0,sizeof(f)); memset(cnt,0,sizeof(cnt)); for (i = 0; i < len; i++) cnt[s[i] - ‘0‘]++; f[0][0] = 1; for (i = 0; i <= MASK; i++) { for (j = 0; j < d; j++) { for (k = 0; k < len; k++) { if ((i & (1 << k)) == 0) f[i | (1 << k)][(j * 10 + s[k] - ‘0‘) % d] += f[i][j]; } } } ans = f[MASK][0]; for (i = 0; i < 10; i++) ans /= fac[cnt[i]]; printf("%lld\n",ans); } return 0; }
标签:sizeof get scan www www. nbsp com \n return
原文地址:https://www.cnblogs.com/evenbao/p/9343189.html