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 ...
随机推荐
- Plugin 'Lombok Plugin' is incompatible with this installation
作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. Installation Error Plugin 'Lombok ...
- Krpano教程tour.xml详解
<krpano version="1.18" //版本号 onstart="" //网页启动时调用的函数 basedir="%FIRSTXML% ...
- c++入门之再次探讨类属性
精辟博文:https://blog.csdn.net/msdnwolaile/article/details/51923859(转载,仅供学习|!)
- UnderWater+SDN论文之六
Protocol Emulation Platform Based on Microservice Architecture for Underwater Acoustic Networks Sour ...
- 用C# BigInteger实现的BigDecimal类,终于可以直接做四则运算了。
https://code.google.com/p/dotnet-big-decimal/ 这是个BigDecimal类的开源项目,支持Operators +, - and *. 俺给改了改,加上了除 ...
- 用友云开放平台之API网关
本文介绍选择API网关应考虑的几方面内容,API网关在微服务框架中的作用,API网关如何选型,用友云开放平台的API网关可以做什么. 随着互联网的快速发展,当前已步入移动互联.物联网时代.企业内部系统 ...
- Windows之系统自带截屏快捷键
Windows之系统自带截屏快捷键 现在我们都习惯了使用QQ截屏,但是有时候电脑没有网络,也就意味着无法登陆QQ,在这个时候再有截屏的需求时,我们就束手无策了. 截取全屏 现在我说以个Windows系 ...
- 自己实现数据结构系列五---BinarySearchTree
一.二分搜索树: 1.代码: public class BST<E extends Comparable<E>> { private class Node{ public E ...
- mysql常用命令行操作(二):表和库的操作、引擎、聚合函数
一.查看.创建.删除数据库 create database library default character set utf8 collate utf8_general_ci; # 创建数据库并设置 ...
- Docker存储驱动Device Mapper,Overlay,AUFS
Docker存储驱动之Device Mapper简介 - BookShu - 博客园https://www.cnblogs.com/styshoo/p/6528762.html Docker存储驱动之 ...