sgu237:Galaxy X: Episode I - Masters of Mind(字符串DP)
来源:互联网 发布:淘宝导航 编辑:程序博客网 时间:2024/05/22 06:30
题目大意:
分析:
AC code:
#include <cstdio>#include <string>#include <cstring>#include <iostream>#define ONLINE_JUDGEusing namespace std;const int INPUT = 259;const int MAXN = INPUT*3;string NOANSWER = "FUCK";char src[INPUT];char str[MAXN];int n;int f[3][MAXN];string ans[3][MAXN];int p = 0, q = 1, r = 2;void change(const string &s, int i){ f[r][i] = s.size(); ans[r][i] = s; }void update(const string &s, int i){ if(f[r][i] > (int)s.size() || (f[r][i]==(int)s.size()&&ans[r][i] > s)) change(s, i);}bool check(const string &s){ for(int i = 0, j = s.size()-1; i < j; ++i, --j) if(s[i] != s[j]) return false; return true;}int main(){ #ifndef ONLINE_JUDGE freopen("sgu237.in", "r", stdin); freopen("sgu237.out", "w", stdout); #endif for(int i = 0 ; i < 10; ++i) NOANSWER += NOANSWER; scanf("%s", src); for(int i = 0, sz = strlen(src); i < sz; ++i) if(src[i] == '!') str[++n] = '?', str[++n] = '?', str[++n] = '?'; else str[++n] = src[i]; for(int i = 1; i <= n; ++i) { if(str[i] == '*') f[1][i] = 0; else f[1][i] = 1, ans[1][i] += (str[i]=='?'?'a':str[i]); } for(int i = 2; i <= n; ++i) { for(int j = 1; j+i-1 <= n; ++j) { char c1, c2; int k = j+i-1; c1 = str[j], c2 = str[k]; if(c1 == '*') { if(c2 == '*') { change(ans[p][j+1], j); update(ans[q][j], j); update(ans[q][j+1], j); } else { change(ans[q][j+1], j); if(c2 == '?') c2 = 'a'; update(c2+ans[q][j]+c2, j); } } else if(c2 == '*') { change(ans[q][j], j); if(c1 == '?') c1 = 'a'; update(c1+ans[q][j+1]+c1, j); } else { if(c1 == '?') { if(c2 == '?') change('a'+ans[p][j+1]+'a', j); else change(c2+ans[p][j+1]+c2, j); } else if(c2 == '?' || c1 == c2) change(c1+ans[p][j+1]+c1, j); else change(NOANSWER, j); } } int t = p; p = q, q = r, r = t; } if(check(ans[q][1])) { cout << "YES" << endl; cout << ans[q][1] << endl; } else cout << "NO" << endl; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
0 0
- sgu237:Galaxy X: Episode I - Masters of Mind(字符串DP)
- sgu 237Galaxy X: Episode I
- CF Trainings Season 1 Episode 6 I (dp)
- murmur of WEG Masters 2006
- If You Could Read My Mind (Episode 115)
- X-mind 破解 方法
- 10 Principles of the CSS Masters
- empire states of mind
- Peace of mind
- hdu_3299_Distant Galaxy( DP )
- On peace of mind 心如止水
- POWER OF THE MASTER MIND
- The Acts of the Mind
- Out of mind - 魔术纸
- The Secret of Strand Hill (Episode 113)
- The Wrath of Achilles (Episode 116)
- First of Its Kind (Episode 201)
- node-haystack Episode-4: Wrapper of libuv
- android 代码混淆导致问题,快速定位
- Vi编辑命令
- iOS开发-retain/assign/strong/weak/copy/mutablecopy/autorelease区别
- aidl ( 四) 各部分代码的执行进程和线程
- 让UILabel的文字顶部对齐
- sgu237:Galaxy X: Episode I - Masters of Mind(字符串DP)
- int变量在最新xcode出现的问题
- Hadoop之——Partitioner编程
- Hibernate数据库写入图片
- hdu1405——The Last Practice
- Datagridview合并单元格
- git add .失败解决办法
- Java Servlet学习笔记(六)Servlet Cookies处理
- hadoop整合mongdb