2013多校第三场 --Pieces--状态压缩DP
来源:互联网 发布:手机相册整理软件 编辑:程序博客网 时间:2024/06/01 09:09
题目大意:删除一个字符串里面的回文子串,问最少需要多少次可以删完整个字符串
题解:其实是个蛮简单的题目,比赛完了艾神一点就会了,比赛的时候就是没想到,比赛的时候没想到状态怎么压缩。。还是经验不够。
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#define maxn (1<<16)using namespace std;int dp[maxn];int statu[maxn],nstatu;int n,T,len;char s[20];int maxStatu;bool check(char *t,int vlen){ int vv=vlen/2; for(int i=0;i<vv;i++)if(t[i]!=t[vlen-i-1])return false; return true;}void init(){ scanf("%s",s); memset(dp,0xf,sizeof(dp)); len=strlen(s); maxStatu=1<<len; int vlen; char ts[20]; nstatu=0; for(int i=1;i<maxStatu;i++) { vlen=0; for(int j=0;j<len;j++) { if((1<<j)&i) { ts[vlen++]=s[j]; } } ts[vlen]='\0'; if(check(ts,vlen))statu[nstatu++]=i; }}void solve(){ dp[0]=0; for(int j=0;j<nstatu;j++) { int st=statu[j]; for(int i=0;i<maxStatu;i++) { if((i&st)==0) { dp[i|st]=min(dp[i|st],dp[i]+1); } } } printf("%d\n",dp[(1<<len)-1]);}int main(){ scanf("%d",&T); while(T--) { init(); solve(); } return 0;}
- 2013多校第三场 --Pieces--状态压缩DP
- 2013 多校第三场 hdu 4628 Pieces
- 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)
- HDUOJ 4628 2013多校第三场第8题 Pieces
- hdu 4628 Pieces (状态压缩+二进制枚举+dp)
- hoj 2662 Pieces Assignment 状态压缩dp入门
- HOJ 2662 Pieces Assignment(状态压缩DP)
- HOJ 2662 Pieces Assignment(状态压缩DP)
- Pieces (状态dp)
- 2013 多校第六场 hdu 4655 Cut Pieces
- hdu 4640 多校第四场 状态压缩+最短路+dp
- Hdu--2544--最短路
- Windows下编译cvBlob (cmake) 和 POCO C++
- Android代码实现APK文件的安装与卸载
- 使用IE滤镜实现css3中rgba让背景色透明的效果
- [二叉树专题]:递归求解二叉树的全部节点数目
- 2013多校第三场 --Pieces--状态压缩DP
- 黑马程序员_面试题2(银行业务调度系统)
- 20-php函数页面引入的方法分析
- hdu 2141 Can you find it? (二分查找)
- [二叉树专题]:递归求解二叉树的叶子节点数目
- 【Visual Studio】在VS2012中使用VSXtra
- placement new
- WinCE6.0 USB Host驱动加载流程详解(一)
- VisualStudio2012 & OpenCV & OpenNi编写运行C++代码使用配置的详细说明