1055: [HAOI2008]玩具取名
题目:
http://www.lydsy.com/JudgeOnline/problem.php?id=1055
dp。d[i][j][k]表示i~j能否缩成字母k。
#include
<
iostream
>
#include
<
cstring
>
#include
<
cstdio
>
#include
<
cstdlib
>
#include
<
cmath
>
using
namespace
std;
const
int
MaxN
=
20
;
const
int
MaxL
=
201
;
int
t[
4
],ch[
4
][MaxN][
2
],l;
bool
d[MaxL][MaxL][
4
];
int
change(
char
c)
{
switch
(c)
{
case
'
W
'
:
return
0
;
case
'
I
'
:
return
1
;
case
'
N
'
:
return
2
;
case
'
G
'
:
return
3
;
}
}
void
init()
{
memset(d,
0
,
sizeof
(d));
for
(
int
i
=
0
;i
<
4
;i
++
)
{
cin
>>
t[i];
}
for
(
int
i
=
0
;i
<
4
;i
++
)
{
for
(
int
j
=
0
;j
<
t[i];j
++
)
{
char
c[
5
];
cin
>>
c;
ch[i][j][
0
]
=
change(c[
0
]);
ch[i][j][
1
]
=
change(c[
1
]);
}
}
char
c[
201
];
cin
>>
c;
l
=
strlen(c);
for
(
int
i
=
0
;i
<
l;i
++
)
{
d[i][i][change(c[i])]
=
1
;
}
}
void
dp()
{
for
(
int
length
=
2
;length
<=
l;length
++
)
{
for
(
int
i
=
0
;i
<
l
-
length
+
1
;i
++
)
{
for
(
int
j
=
0
;j
<
4
;j
++
)
{
for
(
int
k
=
i
+
1
;k
<=
i
+
length
-
1
;k
++
)
{
for
(
int
p
=
0
;p
<
t[j];p
++
)
{
if
(d[i][k
-
1
][ch[j][p][
0
]]
==
1
&&
d[k][i
+
length
-
1
][ch[j][p][
1
]]
==
1
)
{
d[i][i
+
length
-
1
][j]
=
1
;
break
;
}
}
if
(d[i][i
+
length
-
1
][j]
==
1
)
{
break
;
}
}
}
}
}
}
void
write()
{
bool
flag
=
0
;
if
(d[
0
][l
-
1
][
0
]
==
1
)
{
cout
<<
'
W
'
;
flag
=
1
;
}
if
(d[
0
][l
-
1
][
1
]
==
1
)
{
cout
<<
'
I
'
;
flag
=
1
;
}
if
(d[
0
][l
-
1
][
2
]
==
1
)
{
cout
<<
'
N
'
;
flag
=
1
;
}
if
(d[
0
][l
-
1
][
3
]
==
1
)
{
cout
<<
'
G
'
;
flag
=
1
;
}
if
(flag
==
0
)
{
cout
<<
"
The name is wrong!
"
;
}
cout
<<
endl;
}
int
main()
{
init();
dp();
write();
return
0
;
}
posted on 2013-02-15 15:10
Kiro
阅读(113)
评论(0)
编辑
收藏
引用
所属分类:
衡八oj
只有注册用户
登录
后才能发表评论。
相关文章:
1055: [HAOI2008]玩具取名
1054: [HAOI2008]移动玩具
1051: [HAOI2006]受欢迎的牛
1050: [HAOI2006]旅行comf
1046: [HAOI2007]上升序列
1042: [HAOI2008]硬币购物
1037: [ZJOI2008]生日聚会Party
1034: [ZJOI2008]泡泡堂BNB
1029: [JSOI2007]建筑抢修
1027: [JSOI2007]合金
网站导航:
博客园
博客园最新博文
博问
管理
4myOI
再给我一次机会将故事改写。
导航
C++博客
首页
新随笔
联系
聚合
管理
统计
随笔 - 0
文章 - 27
评论 - 0
引用 - 0
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
给我留言
查看公开留言
查看私人留言
文章分类
■
hdu(1)
(rss)
■
poj(2)
(rss)
■
衡八oj(24)
(rss)
■
其他
(rss)
文章档案
■
2013年2月 (17)
■
2013年1月 (3)
■
2012年10月 (3)
■
2012年9月 (1)
■
2012年3月 (1)
■
2012年2月 (2)
搜索
最新评论