某人有一套玩具,并想法给玩具命名。首先他选择WING四个字母中的任意一个字母作为玩具的基本名字。然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很长。
现在,他想请你猜猜某一个很长的名字,最初可能是由哪几个字母变形过来的。

算法:区间dp;

这题是很简单的区间dp;(HA动规真不少)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<algorithm>
#include<cstdlib>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define FILE "dealing"
#define LL long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define pii pair<int,int>
#define piii pair<int,pii >
template<typename T> inline bool chkmin(T &a,T b){return a>b?a=b,true:false;}
template<typename T> inline bool chkmax(T &a,T b){return a<b?a=b,true:false;}
namespace IO{
char *fs,*ft,buf[<<];
inline char gc(){return (fs==ft&&(ft=(fs=buf)+fread(buf,,<<,stdin),fs==ft))?:*fs++;}
inline int read(){
LL x=;int ch=gc();bool f=;
while(ch<''||ch>''){if(ch=='-')f=;ch=gc();}
while(ch<=''&&ch>=''){x=(x<<)+(x<<)+ch-'';ch=gc();}
return f?-x:x;
}
}using namespace IO;
namespace OI{
const int maxn();
char flag[];
int t[];
int f[][][];
int g[][][];
char s[];int n;
void init(){
flag[]='W',flag[]='I',flag[]='N',flag[]='G';
t['W']=,t['I']=,t['N']=,t['G']=;
int cnt[];
char ch[];
up(i,,)scanf("%d",&cnt[i]);
up(i,,)while(cnt[i]--){
scanf("%s",ch);
g[i][t[ch[]]][t[ch[]]]=;
}
scanf("%s",s+);
}
void slove(){
init();
n=strlen(s+);
up(i,,n)f[i][i][t[s[i]]]=;
int j;
up(L,,n)up(i,,n-L+){
j=i+L-;
up(k,i,(j-))up(t,,)up(x,,){
if(f[i][j][t])break;
up(y,,)if(f[i][k][x]&&f[k+][j][y]&&g[t][x][y]){f[i][j][t]=;break;}//转移比较暴力
}
}
bool f1=;
if(f[][n][]){cout<<"W";f1=;}
if(f[][n][]){cout<<"I";f1=;}
if(f[][n][]){cout<<"N";f1=;}
if(f[][n][]){cout<<"G";f1=;}
if(!f1)cout<<"The name is wrong!";
cout<<endl;
return;
}
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
using namespace OI;
slove();
return ;
}

[haoi2008]玩具命名的更多相关文章

  1. 【HAOI2008】玩具命名

    水题大失败 原题: 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自 ...

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

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

  3. BZOJ1055: [HAOI2008]玩具取名

    ... #include<bits/stdc++.h> using namespace std; int q[255]; char s[205]; char p[]={'W','I','N ...

  4. BZOJ 1055 [HAOI2008]玩具取名

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

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

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

  6. bzoj千题计划199:bzoj1055: [HAOI2008]玩具取名

    http://www.lydsy.com/JudgeOnline/problem.php?id=1055 区间DP dp[i][j][k] 表示区间[i,j]能否合成k #include<cst ...

  7. 【BZOJ1055】[HAOI2008]玩具取名(区间DP)

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

  8. DP【洛谷P4290】 [HAOI2008]玩具取名

    P4290 [HAOI2008]玩具取名 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用"WI ...

  9. 【bzoj1055】[HAOI2008]玩具取名

    [bzoj1055][HAOI2008]玩具取名 2014年12月1日3,0111 Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名 ...

随机推荐

  1. 网络数据嗅探工具HexInject

    网络数据嗅探工具HexInject   网络数据嗅探是渗透测试工作的重要组成部分.通过嗅探,渗透人员可以了解足够多的内容.极端情况下,只要通过嗅探,就可以完成整个任务,如嗅探到支持网络登录的管理员帐号 ...

  2. Usaco_Contest_2013_Open_Bovine Problem 1. Bovine Ballet

    Problem 1: Bovine Ballet [Brian Dean, 2013] In an attempt to challenge the stereotypical perception ...

  3. Windows Server 2008R2 设置SMTP邮件转发服务

    最近因业务需求在Windows Server 2008R2server上设置SMTP转发服务,主要是在业务审批过程中邮件通知相关人员审批情况, 1.在server上加入服务 2.打开服务 3.新建一个 ...

  4. linux内核I2C子系统学习(三)

    写设备驱动: 四部曲: 构建i2c_driver 注册i2c_driver 构建i2c_client ( 第一种方法:注册字符设备驱动.第二种方法:通过板文件的i2c_board_info填充,然后注 ...

  5. C 标准库 - <float.h>

    C 标准库 - <float.h> 简介 C 标准库的 float.h 头文件包含了一组与浮点值相关的依赖于平台的常量.这些常量是由 ANSI C 提出的,这让程序更具有可移植性.在讲解这 ...

  6. webpack 项目实战

    步骤一: npm init 步骤二: npm install -D clean-webpack-plugin css-loader extract-text-webpack-plugin html-w ...

  7. Nginx优化指南+LINUX内核优化+linux连接数优化+nginx连接数优化

    Most setup guides for Nginx tell you the basics - apt-get a package, modify a few lines here and the ...

  8. dubbo学习之Hello world

    现在企业中使用dubbo的越来越多,今天就简单的学习一下dubbo,写了一个hello world,教程仅供入门,如要深入学习请上官网 服务提供方: 首先将提供方和消费方都引入jar包,如果使用的是m ...

  9. LINUXFOUNDATION EVENTS

    http://events.linuxfoundation.org/ #lflks This invitation-only event focuses on development and inno ...

  10. jave 金额科学记数法处理

    金额 :amount amount.stripTrailingZeros().toPlainString();