Bzoj 1055 玩具取名(区间DP)
题面
题解
字符很麻烦,不妨用数字代替(比如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;
}
Bzoj 1055 玩具取名(区间DP)的更多相关文章
- BZOJ 1055 玩具取名(区间DP)
很显然的区间DP,定义dp[i][j][k], 如果dp[i][j][k]=1表示字符串[i,j]可以组成k字符. # include <cstdio> # include <cst ...
- Bzoj 1055: [HAOI2008]玩具取名 (区间DP)
Bzoj 1055: [HAOI2008]玩具取名 (区间DP) 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1055 区间动态规划和可 ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- 【BZOJ-1055】玩具取名 区间DP
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1560 Solved: 907[Submit][Statu ...
- BZOJ 1055 玩具取名
Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使 ...
- bzoj1055玩具取名——区间DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1055 区间DP,注意初始化!! 因为没记忆化,TLE了一晚上,区间DP尤其要注意不重复递归! ...
- bzoj1055: [HAOI2008]玩具取名(dp)
1055: [HAOI2008]玩具取名 题目:传送门 简要题意: 就是固定四个字母,给出这四个字母分别可以由哪两个字母组成,然后在给你一个字符串,要求把这个字符串还原成原始的四个字母的其中一个. 题 ...
- BZOJ 1260&UVa 4394 区间DP
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...
- BZOJ 2933([Poi1999]地图-区间Dp)
2933: [Poi1999]地图 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 7 Solved: 7 [ Submit][ Status] ...
随机推荐
- 工作笔记 --->新疆统计分析添加市场管理员相关功能笔记
先上一张大致需求的图 表信息 点击首页 “管理站点”时打开一个窗口 <a href="javascript:void(0);" onclick="javascrip ...
- 【BZOJ4816】【SDOI2017】数字表格 [莫比乌斯反演]
数字表格 Time Limit: 50 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description Doris刚刚学习了fibonac ...
- 洛谷 P3375 【模板】KMP字符串匹配
我这段时间因为字符串太差而被关了起来了(昨晚打cf不会处理字符串现场找大佬模板瞎搞,差点就凉了),所以决定好好补一下字符串的知识QAQ,暂时先学习kmp算法吧~ 题目链接:https://www.lu ...
- 最短路之spfa系列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t ...
- TensorFlow 模型保存和导入、加载
在TensorFlow中,保存模型与加载模型所用到的是tf.train.Saver()这个类.我们一般的想法就是,保存模型之后,在另外的文件中重新将模型导入,我可以利用模型中的operation和va ...
- 微软Azure DevOps 使用docker 持续集成 dotnet
azure 环境设置 登录azure 地址 https://dev.azure.com/ 使用微软账号就可以进行登录. 点击右上角新建项目 项目信息,尽量用小写 创建项目 修改默认的dockerfil ...
- poj 2762 tarjan缩点+拓扑序
2013-09-08 10:00 var m, n :longint; t :longint; f, last :..] of longint; pre, other :..] of longint; ...
- hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit: 200 ...
- python 使用headless chrome滚动截图
from selenium import webdriver from selenium.webdriver.chrome.options import Options import util chr ...
- WiderFace标注格式转PASCAL VOC2007标注格式
#coding=utf-8 import os import cv2 from xml.dom.minidom import Document def create_xml(boxes_dict,ta ...