HDU-4628 Pieces 搜索 | DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4628
数据不大,枚举本质。首先对枚举出回文串,然后用DP或者搜索,这里因为层数不多,用bfs比较好,或者用IDA*。。。
//STATUS:C++_AC_140MS_780KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=(<<)+;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End char s[];
int sta[N],d[N],t[];
int T,len,k,up; bool check(int status)
{
int i,j;
for(i=j=;status;i++,status>>=)
if(status&)t[j++]=i;
for(i=;i<(j>>);i++)
if(s[t[i]]!=s[t[j-i-]])return false;
return true;
} void getsta()
{
int i;
up=(<<(len=strlen(s)))-;
k=;
for(i=;i<=up;i++)
if(check(i))sta[k++]=i;
} int bfs()
{
int i,u,v;
queue<int> q;
q.push();
mem(d,-);d[]=;
while(!q.empty()){
u=q.front();q.pop();
for(i=;i<k;i++){
v=sta[i];
if((u&v)== && d[u|v]==-){
d[u|v]=d[u]+;
q.push(u|v);
if((u|v)==up)return d[u|v];
}
}
}
return -;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%s",s);
getsta();
printf("%d\n",bfs());
}
return ;
}
HDU-4628 Pieces 搜索 | DP的更多相关文章
- HDU 4628 Pieces(DP + 状态压缩)
Pieces 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4628 题目大意:给定一个字符串s,如果子序列中有回文,可以一步删除掉它,求把整个序列删除 ...
- hdu 4628 Pieces
http://acm.hdu.edu.cn/showproblem.php?pid=4628 状态压缩DP 时间复杂度应该是 16*(2^32) 但是运行时要远小于这个数 所以加一定剪枝就可以过 代码 ...
- HDU 4628 Pieces(状态压缩+记忆化搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=4628 题意:给个字符窜,每步都可以删除一个字符窜,问最少用多少步可以删除一个字符窜分析:状态压缩+记忆化搜索 ...
- hdu 4628 Pieces(状态压缩+记忆化搜索)
Pieces Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- [kmp+dp] hdu 4628 Pieces
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4622 Reincarnation Time Limit: 6000/3000 MS (Java/Ot ...
- hdu 4628 Pieces 状态压缩dp
Pieces Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- hdu 4628 Pieces 状压dp
题目链接 枚举所有状态, 1表示这个字符还在原来的串中, 0表示已经取出来了. 代码中j = (j+1)|i的用处是枚举所有包含i状态的状态. #include <iostream> #i ...
- HDU 4628 Pieces(状压DP)题解
题意:n个字母,每次可以删掉一组非连续回文,问你最少删几次 思路:把所有回文找出来,然后状压DP 代码: #include<set> #include<map> #includ ...
- hdu 4614 pieces 状态DP
题意:给你一个长度小于等于16的字符串,每次可以删除一个回文传,问你最少删除干净的字数. 状态+dp dp[i] = min(dp[i],dp[j]+dp[j^i]);(j是i的字串): 连接:htt ...
随机推荐
- Android支付接入(二):移动游戏基地
原地址:http://blog.csdn.net/simdanfeg/article/details/9011863 上篇博文跟大家一起走了一遍支付宝支付,今天我们来看看移动支付.众所周知目前付费通道 ...
- poj 2976 Dropping tests 0/1分数规划
0/1分数规划问题,用二分解决!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> # ...
- BZOJ 3997 TJOI2015 组合数学
分析一下样例就可以知道,求的实际上是从左下角到右上角的最长路 因为对于任意不在这个最长路的上的点,都可以通过经过最长路上的点的路径将这个点的价值减光 (可以用反证法证明) 之后就是一个非常NOIP的D ...
- 移动wabAPP 开发 viewport 注意事项
我们在开发移动设备的网站时,最常见的的一个动作就是把下面这个东西复制到我们的head标签中: <meta name="viewport" content="widt ...
- MyBatis之传入参数parameterType
在MyBatis的select.insert.update.delete这些元素中都提到了parameterType这个属性.MyBatis现在可以使用的parameterType有基本数据类型和Ja ...
- live555源码研究(四)------UserAuthenticationDatabase类
一.UserAuthenticationDatabase类作用 1,用户/密码管理 2,鉴权管理 二.类UserAuthenticationDatabase继承关系图 ...
- Eclipse中查看Android模拟器SD卡目录
· 有时候用到Android模拟器来模拟SD卡相关操作,在Eclipse中可以直接查看SD卡目录: 首先,新建模拟器的时候要创建SD卡,存储的大小根据需要创建: 启动模拟器,在Eclipse中打开视图 ...
- 驱动之路-platform简例按键驱动☆☆☆
一 .重要知识点: ▉1.platform设备模型 从Linux 2.6起引入了一套新的驱动管理和注册机制,platform_device和platform_driver,Linux中大部分的设备驱动 ...
- 【转】Picasso – Android系统的图片下载和缓存类库
来源:http://blog.chengyunfeng.com/?p=492 另一篇参考:http://blog.csdn.net/xu_fu/article/details/17043231 Pic ...
- 基于Android Studio搭建Android应用开发环境
备注:电脑是windows xp系统 1. 安装JDK和环境变量设置 JDK是java development kit,Java JDK下载地址 http://www.oracle.com/t ...