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 ...
随机推荐
- Python异常处理try except
原文地址:https://www.cnblogs.com/init-life/p/9105546.html 异常处理try except 在Python中,异常处理,主要是try except语句,通 ...
- eclipse 执行自带的maven命令无效
原文地址:https://blog.csdn.net/qq_26386171/article/details/78262702 下面加上(前提是你的环境变量里已经配置过) -Dmaven.multiM ...
- 小谈UAT(验收测试)
验收测试人员的测试任务: 1.验收人员是提出需求的人员,所以对需求最为熟悉,最主要测试功能的遗漏或者多余2.系统测试人员重点在测试功能的正确性和非功能的符合性,当然也希望验收人员测试功能的正确性3.因 ...
- PT与PX区别
字体大小的设置单位,常用的有2种:px.pt.这两个有什么区别呢? 先搞清基本概念:px就是表示pixel,像素,是屏幕上显示数据的最基本的点: pt就是point,是印刷行业常用单位,等于1/72英 ...
- 在Linux添加PYTHONPATH方法以及修改环境变量方法
Linux下设置环境变量有三种方法,一种用于当前终端,一种用于当前用户,一种用于所有用户: 一:用于当前终端: 在当前终端中输入: export PATH=$PATH:<你的要加入的路径> ...
- IdentityServer4【QuickStart】之设置和概述
设置和概述 有两个基本的方式来开启一个新的IdentityServer项目: 从头开始 从asp.net Identity模板开始 如果你从头开始,我们提供了一些基于内存中构建的存储,所以你不必一开始 ...
- WSL Windows subsytem linux 的简单学习与使用
1. win10 1709 以上的版本应该都增加上了 ctrl +r 运行 winver 查看版本 2. 添加删除程序 增加 wsl 增加一个功能 3. 打开cmd 输入 bash 即可 4. 可以将 ...
- [转帖]PAT 计算机程序设计能力考试
PAT 计算机程序设计能力考试 https://blog.csdn.net/bat67/article/details/52134211 [官方简介] 计算机程序设计能力考试(Programming ...
- [转帖]再次提醒Google Chrome用户应尽快升级浏览器到72.0.3626.121
再次提醒Google Chrome用户应尽快升级浏览器到72.0.3626.121 转帖地址: https://www.cnbeta.com/articles/tech/825591.htm 国内离线 ...
- IntelliJ IDEA启动Tomcat后,却无法访问Tomcat主页 等一系列问题
1.IntelliJ IDEA启动Tomcat后,却无法访问Tomcat主页 转:http://www.myexception.cn/other/1998827.html https://blog.c ...