Light OJ 1021 - Painful Bases(状态压缩DP)
2015-10-23 20:17
417 查看
题目大意:
给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的。
题目解析:
View Code
给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的。
题目解析:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> using namespace std; typedef long long LL; const int INF = 1e9+7; const int maxn = 1055; LL dp[70000][25];///dp[状态][对k取余后的值] = 种类 int num[20]; char str[20]; int main() { int T, base, K, cas = 1; scanf("%d", &T); while(T --) { scanf("%d %d", &base, &K); scanf("%s", str); memset(dp, 0, sizeof(dp)); for(int i=0; str[i]; i++) { if(str[i] >= 'A' && str[i] <= 'F') num[i] = str[i] - 'A' + 10; else num[i] = str[i] - '0'; } int n = strlen(str); int Lim = (1<<n) - 1; dp[0][0] = 1; for(int i=1; i<=Lim; i++)///每种状态 { for(int j=0; j<n; j++)///判断这种状态的数字是否存在 { if( (i&(1<<j)) ) { int newSta = i - (1<<j); for(int k=0; k<K; k++) { int p = (k*base + num[j])%K; dp[i][p] += dp[newSta][k]; } } } } printf("Case %d: %lld\n",cas++, dp[Lim][0]); } return 0; }
View Code
相关文章推荐
- UVA-11374 Airport Express (dijkstra+枚举)
- aix 11.2.0.4的 rac 中“asm 磁盘组normal冗余模式 + cdp镜像存储”的方式 存在的问题。
- Exception in thread "main" org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to co
- 问题— 修改AFNetworking源文件可接收text/plain的方法
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- Domain=NSCocoaErrorDomain Code=3000 没有找到有Push属性的证书 更新证书失败
- Paint对象使用解析【不断更新中】
- xcode 真机编译codesign failed with exit code 1错误 解决
- WARN Worker: Failed to connect to master
- Saiku国际化总结
- 软件安全测试新武器 ——浅谈基于Dynamic Taint Propagation的测试技术
- AIDL 源码窥探
- explain分析查询
- IIS runs out of work items and causes RPC failures when connecting to a remote UNC path
- int main(int argc,char* argv[])详解
- Mac下通过proxychains-ng配置thunderbird来访问gmail
- FIFA 16 comes in with FIFA trainer that will try
- liunx 下scp出现 Permission denied, please try again 的解决办法
- hive环境搭建 Terminal initialization failed; falling back to unsupported 解决
- lucene Lock obtain timed out: Lock@