[luogu4290 HAOI2008]玩具取名(DP)
2024-08-31 05:28:39
Solution
裸区间DP
Code
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define F(i,a,b) for(register int i=(a);i<=(b);i++)
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int tot,len;
map <char,int> M;
char str[]="!WING",ch[300];
int num[5],sc[300][3],f[300][300][5];
int main() {
F(i,1,4) M[str[i]]=i;
F(i,1,4) num[i]=read();
F(i,1,4) F(j,1,num[i]) sc[++tot][0]=i,scanf("%s",ch+1),sc[tot][1]=M[ch[1]],sc[tot][2]=M[ch[2]];
scanf("%s",ch+1);len=strlen(ch+1);
F(i,1,len) f[i][i][M[ch[i]]]=1;
F(L,1,len) F(i,1,len-L+1) {
int j=i+L-1;
F(k,i,j-1) F(x,1,tot)
f[i][j][sc[x][0]]|=f[i][k][sc[x][1]]&f[k+1][j][sc[x][2]];
}
// F(i,1,len) F(j,i,len) F(k,1,4) cout<<i<<" "<<j<<" "<<k<<" "<<f[i][j][k]<<endl;
bool flag=0; F(i,1,4) if(f[1][len][i]) putchar(str[i]),flag=1;
if(!flag) puts("The name is wrong!");
return 0;
}
最新文章
- Hadoop技巧(03):HostName命名带来的问题
- Cannot assign requested address出现的原因及解决方案
- HDU 3833 YY&#39;s new problem ()
- (转)Ratchet教程:Buttons组件
- 用Zend Studio12 导入在workspace中的项目
- sicily 1027 MJ, Nowhere to Hide 字符串匹配与排序
- python dict{}和set([])
- php+mysql非缓冲查询(如何循环大数组)
- [转]mysql自动定时备份数据库的最佳方法-支持windows系统
- Expert for SQL Server 诊断系列
- Blend4开发:会飞的小鸟
- RecyclerView 配合 DiffUtil,好用到飞起
- Redis入门 (CentOS7 + Redis-3.2.1)
- redis 系列5 数据结构之字典(上)
- iOS 字体下载
- Mybatis运行错误:信息: SQLErrorCodes loaded: [DB2, Derby, H2, HDB, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
- kafka入门1:安装及配置
- df值自由度学习[转载]
- RAID廉价磁盘冗余阵列介绍
- sshpass使用
热门文章
- [Angular] Using ngTemplateOutlet to create dynamic template
- ctags的基本操作总结
- Java 构造时成员初始化的陷阱
- Java 获取随机日期
- leetcode String相关
- PCB决策引擎:多维决策表转决策树
- lodop多打印一页白纸
- Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP
- C#,Java,MD5加密对等实现
- 编写linux 命令行实用工具 shell命令