很显然的区间DP,定义dp[i][j][k], 如果dp[i][j][k]=1表示字符串[i,j]可以组成k字符。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... struct To{int a[][];}to[];
int dp[][][], p[], len, a[];
char wing[]; void init(){p['W'-'A']=; p['I'-'A']=; p['N'-'A']=; p['G'-'A']=; mem(dp,-);}
void dfs(int l, int r)
{
if (~dp[l][r][]) return ;
if (l==r) {dp[l][r][]=; dp[l][r][p[wing[l]-'A']]=; return ;}
FO(i,l,r) {
dfs(l,i); dfs(i+,r);
FOR(j,,) FOR(k,,a[j]) {
int tmp1=to[j].a[k][], tmp2=to[j].a[k][];
if (dp[l][i][tmp1]==&&dp[i+][r][tmp2]==) {dp[l][r][j]=; break;}
}
}
dp[l][r][]=;
return ;
}
int main ()
{
char s[];
init();
scanf("%d%d%d%d",a+,a+,a+,a+);
FOR(i,,a[]) scanf("%s",s), to[].a[i][]=p[s[]-'A'], to[].a[i][]=p[s[]-'A'];
FOR(i,,a[]) scanf("%s",s), to[].a[i][]=p[s[]-'A'], to[].a[i][]=p[s[]-'A'];
FOR(i,,a[]) scanf("%s",s), to[].a[i][]=p[s[]-'A'], to[].a[i][]=p[s[]-'A'];
FOR(i,,a[]) scanf("%s",s), to[].a[i][]=p[s[]-'A'], to[].a[i][]=p[s[]-'A'];
scanf("%s",wing+);
len=strlen(wing+);
dfs(,len);
int flag=;
if (dp[][len][]==) flag=, putchar('W');
if (dp[][len][]==) flag=, putchar('I');
if (dp[][len][]==) flag=, putchar('N');
if (dp[][len][]==) flag=, putchar('G');
if (!flag) {puts("The name is wrong!"); return ;}
putchar('\n');
return ;
}

最新文章

  1. Ubuntu 配置 no-ip
  2. android 导入数据(通讯录)
  3. Oracle connect by 树查询之三(超详细)
  4. latex数字加粗后变宽
  5. mac配置iterm2和ohmyzsh
  6. C#学习笔记:泛型委托Action&lt;T&gt;和Fun&lt;TResult&gt;
  7. postal.js使用
  8. C++中struct和class的总结
  9. 矢量编程——随着MNIST案例
  10. [css]《css揭秘》学习(四)-一个元素实现内圆角边框
  11. 函数&amp;闭包
  12. SSM中(Spring-SpringMVC-Mybatis)(二:整合)
  13. 使用Git将项目托管到码云及从码云导入项目到本地
  14. [Swift]LeetCode436. 寻找右区间 | Find Right Interval
  15. RSA签名的PSS模式
  16. Python 入门基础15 --shutil、shelve、log常用模块2、项目结构
  17. 【repost】图解Javascript上下文与作用域
  18. [ZJOI2007] 仓库建设
  19. hdu 2197 求长度为n的本原串 (快速幂+map)
  20. 10 分钟速成 Python3

热门文章

  1. Making AJAX Applications Crawlable
  2. 20145209刘一阳《网络对抗》实验五:MSF基础应用
  3. C#中访问私有成员--反射
  4. steam更新出错 应用运行中
  5. linux_fdisk命令详解,关于分区的详解
  6. 用wireshark查看 tcpdump 抓取的mysql交互数据
  7. mysql中的直方图采样逻辑
  8. Ping隧道
  9. lintcode671 循环单词
  10. jdbc连接sql server2017进行简单的增、删、改、查操作