poj 2817
来源:互联网 发布:江大网络教育主页 编辑:程序博客网 时间:2024/05/01 06:59
WordStack
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2088 Accepted: 696
Description
As editor of a small-town newspaper, you know that a substantial number of your readers enjoy the daily word games that you publish, but that some are getting tired of the conventional crossword puzzles and word jumbles that you have been buying for years. You decide to try your hand at devising a new puzzle of your own.
Given a collection of N words, find an arrangement of the words that divides them among N lines, padding them with leading spaces to maximize the number of non-space characters that are the same as the character immediately above them on the preceding line. Your score for this game is that number.
Given a collection of N words, find an arrangement of the words that divides them among N lines, padding them with leading spaces to maximize the number of non-space characters that are the same as the character immediately above them on the preceding line. Your score for this game is that number.
Input
Input data will consist of one or more test sets.
The first line of each set will be an integer N (1 <= N <= 10) giving the number of words in the test case. The following N lines will contain the words, one word per line. Each word will be made up of the characters 'a' to 'z' and will be between 1 and 10 characters long (inclusive).
End of input will be indicated by a non-positive value for N .
The first line of each set will be an integer N (1 <= N <= 10) giving the number of words in the test case. The following N lines will contain the words, one word per line. Each word will be made up of the characters 'a' to 'z' and will be between 1 and 10 characters long (inclusive).
End of input will be indicated by a non-positive value for N .
Output
Your program should output a single line containing the maximum possible score for this test case, printed with no leading or trailing spaces.
Sample Input
5 abc bcd cde aaa bfcde 0
Sample Output
8
Hint
Note: One possible arrangement yielding this score is:
aaa
abc
bcd
cde
bfcde
Source
Mid-Atlantic 2005
分析:状态压缩DP,把取单词的情况用二进制表示,容易得到状态转移方程
f[i][s|pow[i]]=max(f[i][s|pow[i]],f[j][s]+w[i][j]),其中 s为当前状态,,pow[i]=1<<(i-1);pow[i]&s==0,pow[j]&s>0,w[i][j]为单词i,j相邻的值
还是好挫地wrong了一次,最近实在是没状态啊~~~
找来一组数据:
10
abc
bc
abcd
bbc
bcd
dbc
a
bacd
ebdac
ac
答案:19
代码:
- poj 2817
- (2817)POJ
- POJ 2817 (状态DP)
- poj 2817 wordstack
- POJ-2817:木棒
- poj 2817 状态DP
- (2817)POJ-状态压缩
- POJ 2817 WordStack
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- jsp中的日期问题及其它
- url路径参数带中文的乱码解决(前后台均为UTF-8)
- JSP 语法详解
- VB.NET 之 Chr 函数
- C# graphicspath 翻转
- poj 2817
- 如何配置iis?
- C语言预处理器
- 去除iPhone icon的光晕效果
- 单向加密算法
- Oracle 10.2.0.1 升级到 10.2.0.4
- Oracle创建删除的外键脚本
- java对象占内存大小
- 在C#中如何创建写入XML文件示例