若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1078: English Game

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,109

题目描述

p { margin-bottom: 0.21cm; }
This English game is a simple English words connection game.
The rules are as follows: there are N English words in a dictionary, and every word has its own weight v. There is a weight if the corresponding word is used. Now there is a target string X. You have to pick some words in the dictionary, and then connect them to form X. At the same time, the sum weight of the words you picked must be the biggest.

输入

p { margin-bottom: 0.21cm; }
There are several test cases. For each test, N (1<=n<=1000) and X (the length of x is not bigger than 10000) are given at first. Then N rows follow. Each row contains a word wi (the length is not bigger than 30) and the weight of it. Every word is composed of lowercases. No two words in the dictionary are the same.

输出

h2 { margin-top: 0.05cm; margin-bottom: 0.05cm; color: rgb(0, 0, 0); line-height: 0.78cm; page-break-inside: avoid; }h2.western { font-family: "Times New Roman",serif; font-size: 14pt; }h2.cjk { font-family: "宋体","SimSun"; font-size: 14pt; font-style: normal; }h2.ctl { font-family: "Calibri",sans-serif; font-size: 16pt; }p { margin-bottom: 0.21cm; }
For each test case, output the biggest sum weight, if you could not form the string X, output -1.

样例输入

1 aaaa
a 2
3 aaa
a 2
aa 5
aaa 6
4 abc
a 1
bc 2
ab 4
c 1
3 abcd
ab 10
bc 20
cd 30
3 abcd
cd 100
abc 1000
bcd 10000

样例输出

8
7
5
40
-1

参考代码

暂无

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Skip Dreams孤独患者
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist