博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-4628 Pieces 搜索 | DP
阅读量:4494 次
发布时间:2019-06-08

本文共 2243 字,大约阅读时间需要 7 分钟。

  题目链接:

  数据不大,枚举本质。首先对枚举出回文串,然后用DP或者搜索,这里因为层数不多,用bfs比较好,或者用IDA*。。。

1 //STATUS:C++_AC_140MS_780KB  2 #include 
3 #include
4 #include
5 //#include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20 #include
21 #include
22 #include
23 using namespace std; 24 //using namespace __gnu_cxx; 25 //define 26 #define pii pair
27 #define mem(a,b) memset(a,b,sizeof(a)) 28 #define lson l,mid,rt<<1 29 #define rson mid+1,r,rt<<1|1 30 #define PI acos(-1.0) 31 //typedef 32 typedef __int64 LL; 33 typedef unsigned __int64 ULL; 34 //const 35 const int N=(1<<16)+10; 36 const int INF=0x3f3f3f3f; 37 const int MOD=100000,STA=8000010; 38 const LL LNF=1LL<<60; 39 const double EPS=1e-8; 40 const double OO=1e15; 41 const int dx[4]={-1,0,1,0}; 42 const int dy[4]={ 0,1,0,-1}; 43 const int day[13]={ 0,31,28,31,30,31,30,31,31,30,31,30,31}; 44 //Daily Use ... 45 inline int sign(double x){ return (x>EPS)-(x<-EPS);} 46 template
T gcd(T a,T b){ return b?gcd(b,a%b):a;} 47 template
T lcm(T a,T b){ return a/gcd(a,b)*b;} 48 template
inline T lcm(T a,T b,T d){ return a/d*b;} 49 template
inline T Min(T a,T b){ return a
inline T Max(T a,T b){ return a>b?a:b;} 51 template
inline T Min(T a,T b,T c){ return min(min(a, b),c);} 52 template
inline T Max(T a,T b,T c){ return max(max(a, b),c);} 53 template
inline T Min(T a,T b,T c,T d){ return min(min(a, b),min(c,d));} 54 template
inline T Max(T a,T b,T c,T d){ return max(max(a, b),max(c,d));} 55 //End 56 57 char s[18]; 58 int sta[N],d[N],t[18]; 59 int T,len,k,up; 60 61 bool check(int status) 62 { 63 int i,j; 64 for(i=j=0;status;i++,status>>=1) 65 if(status&1)t[j++]=i; 66 for(i=0;i<(j>>1);i++) 67 if(s[t[i]]!=s[t[j-i-1]])return false; 68 return true; 69 } 70 71 void getsta() 72 { 73 int i; 74 up=(1<<(len=strlen(s)))-1; 75 k=0; 76 for(i=1;i<=up;i++) 77 if(check(i))sta[k++]=i; 78 } 79 80 int bfs() 81 { 82 int i,u,v; 83 queue
q; 84 q.push(0); 85 mem(d,-1);d[0]=0; 86 while(!q.empty()){ 87 u=q.front();q.pop(); 88 for(i=0;i

 

转载于:https://www.cnblogs.com/zhsl/p/3233506.html

你可能感兴趣的文章
PyCharm命令行输入
查看>>
ThinkPHP5.0 模型更新操作
查看>>
鼠标经过时 表格行的背景色更改
查看>>
Codeforces Round #248 (Div. 2) C. Ryouko's Memory Note
查看>>
js数组操作总结
查看>>
九九乘法表
查看>>
写个.net开发者的Linux迁移指南
查看>>
搭建使用SVN的快速教程
查看>>
openlayers显示区域
查看>>
适配器模式学习
查看>>
android脚步--Relativelayout设置
查看>>
第一周博客作业2018091-2
查看>>
Spring boot JPA读取数据库方法
查看>>
TEA对称加密算法
查看>>
Dell笔记本刷回低版本bios的方法
查看>>
redis资料
查看>>
《自己动手写docker》之namespace部门实验
查看>>
Vim学习总结
查看>>
maven也是Apache开发的,也是java开发的。maven需要你本地系统JDK的支持
查看>>
垂直同步v-sync
查看>>