题面

题解

字符很麻烦,不妨用数字代替(比如1代表'W')

const char c[5] = {0, 'W', 'I', 'N', 'G'};

接着,像这种两个子串可以合并成另一个子串的题可以考虑区间$DP$

设$bool$数组$f_{i,j,k}$表示区间$[l,r]$能否合成单个字符$c_k$

于是就可以套区间$DP$的板子了

#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::sort; using std::swap;
using std::unique; using std::lower_bound;
using std::map;
typedef long long ll; template<typename T>
void read(T &x) {
int flag = 1; x = 0; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
} const int Len = 2e2 + 10, _ = 5;
const char c[5] = {0, 'W', 'I', 'N', 'G'};
char s[Len]; bool p, f[Len][Len][_];
int num[_], list[Len][_], tot, len;
int check(char x) { for(int i = 1; i <= 4; ++i) if(x == c[i]) return i; } int main () {
for(int i = 1; i <= 4; ++i) read(num[i]);
for(int i = 1; i <= 4; ++i)
for(int j = 1; j <= num[i]; ++j) {
char ss[5]; scanf("%s", ss);
list[++tot][0] = i;
list[tot][1] = check(ss[0]);
list[tot][2] = check(ss[1]);
}
scanf("%s", s + 1), len = strlen(s + 1);
for(int i = 1; i <= len; ++i) f[i][i][check(s[i])] = true;
for(int k = 1; k <= len; ++k)
for(int i = 1; i + k <= len; ++i) {
int j = i + k;
for(int p = i; p < j; ++p)
for(int l = 1; l <= tot; ++l)
if(f[i][p][list[l][1]] && f[p + 1][j][list[l][2]])
f[i][j][list[l][0]] = true;
}
for(int i = 1; i <= 4; ++i)
if(f[1][len][i]) putchar(c[i]), p = true;
if(!p) printf("The name is wrong!");
puts("");
return 0;
}

最新文章

  1. 关于input标签和placeholder在IE8,9下的兼容问题
  2. Linux服务器之间的目录共享
  3. 使用PowerDesigner把oom设计图导出jpg格式的图片
  4. 群内大神与你交流WEB经验 业内专家指点就职技巧
  5. Hbase中的BloomFilter(布隆过滤器)
  6. [Tool] Fiddle2基本使用
  7. 欧几里得算法与扩展欧几里得算法_C++
  8. insertAfter()
  9. 使用Qmake在树莓派上开发Opencv程序
  10. HTML输出 一 控制列背景颜色
  11. windows下使用xampp一键安装apache+php运行环境
  12. dedecms幻灯片调用图片模糊的解决办法
  13. 关于C语言文件操作
  14. Paxos 算法
  15. 游戏AI之决策结构—有限状态机/行为树(2)
  16. layui在open弹出层回显,解决动态select数据回显问题
  17. Confluence 6 理解你许可证的用户数
  18. Oracle 11g 静默安装脚本
  19. pyspider源码解读--调度器scheduler.py
  20. pycharm 配置服务器,脚本,测试文件

热门文章

  1. uva 1506 Largest Rectangle in a Histogram
  2. MyBatis框架的使用及源码分析(一) 配置与使用
  3. spring怎么实现单例模式?
  4. CPU上下文切换的次数和时间(context switch)
  5. 【BZOJ4236】JOIOJI [DP]
  6. javascript 事件绑定
  7. Cordova入门
  8. hdu 3790 最短路径问题(双重权值,dijkstra算法)
  9. DIV+CSS左右列高度自适应问题
  10. USB 3.1 與 USB Type-C 解釋