bzoj1055: [HAOI2008]玩具取名(dp)
1055: [HAOI2008]玩具取名
题目:传送门
简要题意:
就是固定四个字母,给出这四个字母分别可以由哪两个字母组成,然后在给你一个字符串,要求把这个字符串还原成原始的四个字母的其中一个。
题解:
一开始看题有点瞎...想了想是一道超级大难题...
其实就是一个很简单的DP...
定义发f[i][j][s]:表示在字符串中i~j这个区间是否可以组合成为字符s
转移很容易就可以想出来:因为如果f[i][k][s1]==f[k+1][j][s2]==1(i<=k<=j) && s1和s2可以组成s,那么f[i][j][s]=1;
O(n^4)...大水题
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
char s[];
struct node
{
char s1,s2,id;
}st[];
bool f[][][];
int main()
{
int W,I,N,G;bool bk=false;
scanf("%d%d%d%d",&W,&I,&N,&G);
int len=;
for(int i=;i<=W;i++)
scanf("%s",s+),st[++len].s1=s[],st[len].s2=s[],st[len].id='W';
for(int i=;i<=I;i++)
scanf("%s",s+),st[++len].s1=s[],st[len].s2=s[],st[len].id='I';
for(int i=;i<=N;i++)
scanf("%s",s+),st[++len].s1=s[],st[len].s2=s[],st[len].id='N';
for(int i=;i<=G;i++)
scanf("%s",s+),st[++len].s1=s[],st[len].s2=s[],st[len].id='G';
scanf("%s",s+);
int len1=strlen(s+);
memset(f,,sizeof(f));
for(int i=;i<=len1;i++)f[i][i][s[i]]=true;
for(int i=;i<=len1;i++)//长度
for(int l=;l<=len1-i+;l++)//左端点
{
int r=l+i-;
for(int j=l;j<=r;j++)//断点
for(int k=;k<=len;k++)//枚举所有种类的字符串
if(f[l][j][st[k].s1] && f[j+][r][st[k].s2])
f[l][r][st[k].id]=true;
}
W='W';I='I';N='N';G='G';
if(f[][len1][W])printf("W"),bk=true;
if(f[][len1][I])printf("I"),bk=true;
if(f[][len1][N])printf("N"),bk=true;
if(f[][len1][G])printf("G"),bk=true;
if(bk==false)printf("The name is wrong!\n");
return ;
}
bzoj1055: [HAOI2008]玩具取名(dp)的更多相关文章
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- BZOJ1055: [HAOI2008]玩具取名
... #include<bits/stdc++.h> using namespace std; int q[255]; char s[205]; char p[]={'W','I','N ...
- bzoj千题计划199:bzoj1055: [HAOI2008]玩具取名
http://www.lydsy.com/JudgeOnline/problem.php?id=1055 区间DP dp[i][j][k] 表示区间[i,j]能否合成k #include<cst ...
- [bzoj1055][HAOI2008]玩具取名_区间dp
玩具取名 bzoj-1055 HAOI-2008 题目大意:给你一个用W,I,N,G组成的字符串,给你一些这四个字符之间的变换规则,每一个变换规则都是由一个字符变成两个字符,问这个字符串是否可能是由一 ...
- BZOJ1055[HAOI2008]玩具取名 【区间dp + 记忆化搜索】
题目 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后 他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够 ...
- 【题解】 bzoj1055: [HAOI2008]玩具取名 (动态规划)
bzoj1055,懒得复制,戳我戳我 Solution: 区间动规(以后开始动规会在solution前面标注是啥动规 我觉的这道题挺难想了,但其实状态定义了一下子就出来了(还是不行啊) 我们定义状态\ ...
- [luogu4290 HAOI2008]玩具取名(DP)
传送门 Solution 裸区间DP Code #include <map> #include <cmath> #include <cstdio> #include ...
- 【记忆化搜索】bzoj1055 [HAOI2008]玩具取名
f(l,r,c)表示sl...sr能否被合成字符c. #include<cstdio> #include<cstring> using namespace std; int m ...
- 【BZOJ1055】[HAOI2008]玩具取名(区间DP)
[HAOI2008]玩具取名 题目描述 某人有一套玩具,并想法给玩具命名.首先他选择\(WING\)四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用" ...
随机推荐
- Intellij idea 自动完成的变量名称首字母变为小写
Intellij idea 自动完成的变量名称首字母变为小写 好像没有什么好的自动办法,自己输入一个小写的字母吧,然后Idea会出提示.
- Swift基础--定位
// // ViewController.swift // JieCoreLocation // // Created by jiezhang on 14-10-4. // Copyright (c) ...
- 用LayerDrawable实现两个图片的叠加效果
Drawable[] layers = new Drawable[2]; layers[0] = new ColorDrawable(primaryColor); layers[1] = new Co ...
- Codeforces 13C Sequence dp
题目链接:http://codeforces.com/problemset/problem/13/C 题意: 给定n长的序列 每次操作能够给每一个数++或-- 问最少须要几步操作使得序列变为非递减序列 ...
- Android解决ScrollView视图导致其底部的布局栏被推到上边的问题
近期有个xml布局文件,我说下大概意思: <ScrollView> ...... </ScrollView> <RelativeLayout> ...... < ...
- Codeforce 163 A. Substring and Subsequence DP
A. Substring and Subsequence One day Polycarpus got hold of two non-empty strings s and t, consist ...
- Medium上的文章
Welcome to Medium, a place to read, write, and interact with the stories that matter most to you. 网站 ...
- systemd服务管理---systemctl命令列出所有服务
1.列出系统所有服务 #systemctl list-units --all --type=service
- [poj 2185] Milking Grid 解题报告(KMP+最小循环节)
题目链接:http://poj.org/problem?id=2185 题目: Description Every morning when they are milked, the Farmer J ...
- sas与mysql连接方法
2012年8月11日 sas 9.1.3 版本 与mysql 连接 测试,可以与数据库连接1 通过odbc 直接连通 pass through connect to odbc create tabl ...