hdu 4628 Pieces(状压dp)
来源:互联网 发布:c语言心形图案代码动态 编辑:程序博客网 时间:2024/06/07 02:24
题目链接:hdu 4628 Pieces
代码
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 20;const int maxs = (1<<16) + 6;const int inf = 0x3f3f3f3f;int N, dp[maxs], vis[maxs];char str[maxn];bool judge(int s) { int a[maxn], n = 0; for (int i = 0; i < N; i++) if (s&(1<<i)) a[n++] = i; for (int i = 0; i < n/2; i++) if (str[a[i]] != str[a[n-i-1]]) return false; return true;}void init () { scanf("%s", str); N = strlen(str); memset(vis, 0, sizeof(vis)); for (int i = 0; i < (1<<N); i++) if (judge(i)) vis[i] = 1;}int solve () { memset(dp, inf, sizeof(dp)); dp[0] = 0; for (int i = 0; i < (1<<N); i++) { int s = i^((1<<N)-1); for (int j = s; j; j = (j-1)&s) { if (vis[j]) { int v = i|j; dp[v] = min(dp[v], dp[i]+1); } } } return dp[(1<<N)-1];}int main () { int cas; scanf("%d", &cas); while (cas--) { init(); printf("%d\n", solve()); } return 0;}
0 0
- hdu 4628 Pieces(状压dp)
- [状压dp] hdu 4628 Pieces
- HDU-4628 Pieces 状压DP
- HDU 4628 Pieces (状压DP)
- hdu - 4628 - Pieces(状态压缩dp)
- HDU 4628 Pieces(状态压缩dp)
- hdu 4628 Pieces(状态压缩DP)
- hdu 4628 Pieces (状态压缩dp)
- hdu 4628 - Pieces(压缩dp)
- hdu 4628 Pieces 集合DP
- [kmp+dp] hdu 4628 Pieces
- hdu(4628)Pieces
- hdu 4628 Pieces (状态压缩dp)
- hdu 4628 Pieces 状态压缩DP
- HDU 4628 Pieces(状态压缩DP)
- hdu 4655 Cut Pieces(DP 贪心)
- Pieces (状态dp)
- hdu 4628 Pieces (状态压缩+二进制枚举+dp)
- android基础控件
- 九度oj-1002-Grading
- 去除系统快捷方式箭头
- 为什么String是不可变的
- CodeTyphon32中自带例子源码:演示自定义错误提示
- hdu 4628 Pieces(状压dp)
- 深入理解计算机系统(5)
- UVA 11853(找连通块)
- Eclipse查找替换巧妙技巧用法
- DEPRECATED: Use of this script to execute hdfs command is deprecated.
- Coolite ComboBox中显示树
- 图形化控制台连接mysql报错1042解决办法
- 没有躲过的坑--获取一张图片的width和height
- hdu 4641 K-string(后缀自动机 + 并查集)