CF 401D Roman and Numbers
来源:互联网 发布:java代理模式使用场景 编辑:程序博客网 时间:2024/05/22 04:29
状态压缩,第一维记录哪些位置的数字用过,第二维记录当前状态余数为多少。在第三层循环时,若数字x前面已经用过,则不用再次计数,因为没有区别,如果计入则最后需要除以每种数的阶乘。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;typedef long long LL;LL dp[1 << 18][103];int v[15];char a[20];int m;int main(){ scanf("%s%d", a, &m); memset(dp, 0, sizeof(dp)); dp[0][0] = 1; int len = strlen(a); for(int i = 0; i < (1 << len); i++){ for(int j = 0; j < m; j++){ memset(v, 0, sizeof(v)); for(int k = 0; k < len; k++){ int x = a[k] - '0'; if(i & (1 << k))continue; if(i == 0 && x == 0)continue; if(v[x])continue; v[x] = 1; dp[i | (1 << k)][(j * 10 + x) % m] += dp[i][j]; } } } printf("%I64d\n", dp[(1 << len) - 1][0]); return 0;}
0 0
- CF 401D Roman and Numbers
- CF 401D - Roman and Numbers
- cf 401D. Roman and Numbers 数位dp,状压
- CodeForces 401D Roman and Numbers
- codeforces 401D Roman and Numbers
- codeforces 401D Roman and Numbers(状态压缩)
- Codeforces 401D Roman and Numbers(记忆化搜索)
- [数位dp] Codeforces 401D Roman and Numbers
- [Codefoces 401D]Roman and Numbers 数位dp
- Codeforce 401D Roman and Numbers[数位DP+状态压缩]
- Codeforces 401D Roman and Numbers【状压dp】
- Codeforces 401D Roman and Numbers 状压DP
- CodeForces 401D Roman and Numbers【数位dp+状态压缩】
- codeforces 401D Roman and Numbers (数位dp)
- codeforces #235 D. Roman and Numbers 题解
- codeforces 401D D. Roman and Numbers(状态压缩dp+数论)
- Codeforces Round #235 (Div. 2) ----D. Roman and Numbers
- Codeforces Round #235 (Div. 2) D. Roman and Numbers
- HDOJ1019 Least Common Multiple
- Java中abstract和interface的区别
- 待看!!!
- 网站GZIP压缩
- mongodb 索引
- CF 401D Roman and Numbers
- 字符串+第i个字符+字符串
- Oracle 主键
- Rich Text
- 9、OC文件管理
- 独辟蹊径的编程思维——“拿来主义”编程
- subversion知识库
- 课本小Demo,ButtonDmeo
- 男子买福特轿车半月修3回 4S店:与用油质量有关