Aizu2130-Billion Million Thousand-dp
用dp求出最大的表达,再用dp求出。//然而并没有想出来
#include <cstdio>
#include <string>
#include <algorithm>
#include <iostream> using namespace std; const int INF = 0x3f3f3f3f;
const int maxn = ; int N,v[maxn],len[maxn];
int dp[maxn]; string s[maxn],str; int main()
{
int cas = ;
while(cin >> N && N)
{
for(int i=;i<N;i++)
{
cin >> s[i] >> v[i];
len[i] = s[i].length();
}
cin >> str;
int length = str.length(); for(int i=;i<=length;i++) dp[i] = -INF;
dp[] = ; for(int i=;i<=length;i++)
{
for(int j=;j<N;j++)
{
int End = i - len[j];
if(End>= && dp[End]>= && str.substr(End,len[j]) == s[j])
{dp[i] = max(dp[i],dp[End]+v[j]);}
}
} int mx = dp[length]; for(int i=;i<=mx;i++) dp[i] = INF;
dp[] = ; for(int i=;i<N;i++)
{
for(int j=;j<=mx-v[i];j++)
dp[j+v[i]] = min(dp[j+v[i]] , dp[j]+len[i]);
}
cout << "Case "<<cas++<< ": " << dp[mx] << endl;
}
}
Aizu2130-Billion Million Thousand-dp的更多相关文章
- 【LeetCode】273. Integer to English Words
Integer to English Words Convert a non-negative integer to its english words representation. Given i ...
- leetcode@ [273] Integer to English Words (String & Math)
https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to its englis ...
- Integer to English Words 解答
Question Convert a non-negative integer to its english words representation. Given input is guarante ...
- LeetCode Integer to English Words
原题链接在这里:https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to it ...
- 273 Integer to English Words 整数转换英文表示
将非负整数转换为其对应的英文表示,给定的输入是保证小于 231 - 1 的.示例:123 -> "One Hundred Twenty Three"12345 -> & ...
- LeetCode 273. Integer to English Words
原题链接在这里:https://leetcode.com/problems/integer-to-english-words/description/ 题目: Convert a non-negati ...
- words
conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...
- 使用千位分隔符(逗号)表示web网页中的大数字
做手机端页面我们常常遇到数字,而在Safari浏览器下这些数字会默认显示电话号码,于是我们就用到了补坑的方法加入<meta>标签: <meta name="format-d ...
- HDU 4169 树形DP
Wealthy Family Problem Description While studying the history of royal families, you want to know ho ...
- How to Pronounce Numbers 20 – 1 Billion
How to Pronounce Numbers 20 – 1 Billion Share Tweet Share Tagged With: Numbers Numbers are something ...
随机推荐
- zookeeper-分布式锁的代码实现-【每日五分钟搞定大数据】
本文涉及到几个zookeeper简单的知识点,永久节点.有序节点.watch机制.比较基础,熟悉的就别看了跳过这篇吧 每个线程在/locks节点下创建一个临时有序节点test_lock_0000000 ...
- Docker入门 第一课 --.Net Core 使用Docker全程记录
微服务架构无疑是当前最火热的开发架构,而Docker作为微服务架构的首选工具,是我们必须要了解掌握的. 我通过一天的时间,网上查文档,了解基础概念,安装Docker,试验Docker命令,通过Dock ...
- 2018 Multi-University Training Contest 2
题目链接:2018 Multi-University Training Contest 2 6318 Swaps and Inversions 题意:sum=x*逆序个数+交换次数*y,使sum最小 ...
- 书城项目第五阶段---book表的curd
JavaEE三层架构分析 MVC
- Spring Data Elasticsearch 和 x-pack 用户名/密码验证连接
Elasticsearch Java API 客户端连接 一个是TransportClient,一个是NodeClient,还有一个XPackTransportClient TransportClie ...
- Telnet服务器和客户端请求处理
Telnet服务器和客户端请求处理 本文的控制台项目是根据SuperSocket官方Telnet示例代码进行调试的,官方示例代码:Telnet示例. 开始我的第一个Telnet控制台项目之旅: 创建控 ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.bw.mapper.BillMapper.getBillList at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:225
这个错误是没有找到映射文件 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.b ...
- VO和DO转换(三) Dozer
VO和DO转换(一) 工具汇总 VO和DO转换(二) BeanUtils VO和DO转换(三) Dozer VO和DO转换(四) MapStruct 可参考的资料: dozer官网 Dozer(Jav ...
- shell脚本--php执行普通shell命令
这里只演示一些普通的shell命令,一些需要root用户权限执行的命令,请参考:php以root权限执行shell命令 php执行shell命令,可以使用下面几个函数: string system ( ...
- 简单封装mongodb
首先安装mongodb npm i mongodb --save 简单封装,在modules目录下新建db.js var MongoClient=require('mongodb').MongoCl ...