不难想,就是处理起来比较麻烦

设f[i][j][k]为是否可以把区间(i,j)合并为k,初始状态是f[i][j][s[i]]=1,转移的话另一段枚举长度x,向(i-x,j),(i,j+x)转移

把四个字符hash成1234比较好写(大概

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=205;
int n,c[10],mp[N];
bool f[N][N][10],fl,a[10][10][10];
char ch[5],s[N],rl[10];
int main()
{
mp['W']=1,mp['I']=2,mp['N']=3,mp['G']=4;
rl[1]='W',rl[2]='I',rl[3]='N',rl[4]='G';
scanf("%d%d%d%d",&c[1],&c[2],&c[3],&c[4]);
for(int i=1;i<=4;i++)
for(int j=1;j<=c[i];j++)
{
scanf("%s",ch+1);
a[mp[ch[1]]][mp[ch[2]]][i]=1;
}
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++)
s[i]=mp[s[i]],f[i][i][s[i]]=1;
for(int l=1;l<n;l++)
for(int i=1;i+l-1<=n;i++)
{
int j=i+l-1;
for(int k=1;k<=4;k++)
if(f[i][j][k])
{
for(int x=1;x<=l&&j+x<=n;x++)
for(int y=1;y<=4;y++)
if(f[j+1][j+x][y])
for(int z=1;z<=4;z++)
if(a[k][y][z])
f[i][j+x][z]=1;
for(int x=1;x<=l&&i-x>=1;x++)
for(int y=1;y<=4;y++)
if(f[i-x][i-1][y])
for(int z=1;z<=4;z++)
if(a[y][k][z])
f[i-x][j][z]=1;
}
}
for(int i=1;i<=4;i++)
if(f[1][n][i])
printf("%c",rl[i]),fl=1;
if(!fl)
puts("The name is wrong!");
return 0;
}

bzoj 1055: [HAOI2008]玩具取名【区间dp】的更多相关文章

  1. Bzoj 1055: [HAOI2008]玩具取名 (区间DP)

    Bzoj 1055: [HAOI2008]玩具取名 (区间DP) 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1055 区间动态规划和可 ...

  2. [BZOJ 1055][HAOI2008]玩具取名(DP)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1055 分析: 比较难想的dp f[i][j][c]表示i..j能否压缩成字符c 那么怎 ...

  3. bzoj 1055 [HAOI2008]玩具取名(区间DP)

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1258  Solved: 729[Submit][Statu ...

  4. BZOJ1055: [HAOI2008]玩具取名[区间DP]

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Statu ...

  5. BZOJ 1055 [HAOI2008]玩具取名

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1119  Solved: 653[Submit][Statu ...

  6. [BZOJ 1055] [HAOI2008] 玩具取名 【记忆化搜索】

    题目链接:BZOJ - 1055 题目分析 这种类似区间 DP 的记忆化搜索都是很相近的,比如字符串压缩和字符串扩展都差不多. 都是将现在 Solve 的区间分成子区间,再求解子区间. 这道题 Sol ...

  7. [LUOGU] P4290 [BZOJ] 1055 [HAOI2008]玩具取名

    题目描述 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用"WING"中任意两个字母代 ...

  8. 【BZOJ】1055: [HAOI2008]玩具取名(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1055 我竟然都没往dp这个方向想.....百度了下看到标题是dp马上就会转移了QAQ... 设d[i ...

  9. BZOJ 1055: [HAOI2008]玩具取名(记忆化搜索)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1055 题意: 思路:记忆化搜索. #include<iostream> #include ...

随机推荐

  1. php 之mysql安全

    php 之mysql安全 原文:https://www.cnblogs.com/mafeng/p/5939329.html. 请浏览原文. 一.服务器配置方面. (1) 打开php的安全模式 php的 ...

  2. 原生js中stopPropagation,preventDefault,return false的区别

    1.stopPropagation:阻止事件的冒泡,但不阻止事件的默认行为. 最好莫过于用例子说明: <div id='div'  onclick='alert("div") ...

  3. loj6157 A^B Problem (并查集)

    题目: https://loj.ac/problem/6157 分析: 这种树上异或,一般是采用分位考虑,但是这题即使分位,也会发现非常不好处理 这里考虑维护一个点到其根的路径的异或值 用并查集去检测 ...

  4. Linux下使用Curl调用Java的WebService接口

    其实只要是标准的WSDL的SOA接口WebService都可以用. 调用方式: 注意:上面的方式不包括加密或者登录的,其实SOA有一套完整的加密方式. curl -H'Content-Type: te ...

  5. Eclipse的JQuery提示插件-Spket(别试了,没什么效果,且安装设置麻烦)

    参考: http://www.cnblogs.com/shulin/archive/2010/08/09/1796146.html 我测试了,但是没用起来,原因有如下几点: 1.配置复杂,且提示效果不 ...

  6. 【Nginx】如何建立新连接

    处理新连接事件的回调函数是ngx_event_accept,原型如下: void ngx_event_accept(ngx_event_t *ev) 具体流程如下: 1)首先调用accept方法试图建 ...

  7. 【APUE】vim常用命令

    转自:http://coolshell.cn/articles/5426.html 基本命令: i → Insert 模式,按 ESC 回到 Normal 模式. x → 删当前光标所在的一个字符. ...

  8. maven 的编译插件的配置

    原文: https://stackoverflow.com/questions/29258141/maven-compilation-error-use-source-7-or-higher-to-e ...

  9. Prime Distance(二次筛素数)

    Description The branch of mathematics called number theory is about properties of numbers. One of th ...

  10. 以Java属性文件的格式创建Hibernate的配置文件和DTD特殊符号作用

    演示样例代码 hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.connection.driver_class=com.my ...