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 ...
随机推荐
- 【asp.net core mvc + angular6实战】 - 1. 环境搭建
为什么打算写这些文章? 没有为什么,只是为了学习Angular和更了解.Net Core等技术 需要用到的技术? 后端使用.Net Core 2.1 + EF Core 2.1 + Mysql 5.7 ...
- 北京教育软件创业公司招 .net工程师
北京教育软件创业公司,招 .net工程师,月工资2万左右,有合适的朋友帮忙推荐下,要求水平稍高一些的.产品目前用Winform开发的.创始人两个清华,一个北大.老板在美国待了七年回来的,爱人在清华教书 ...
- 【内存溢出】Maven编译时内存溢出的问题解决方式
原文地址:https://www.cnblogs.com/sunny3096/p/7524635.html 编译源码时报出java.lang.OutOfMemoryError: Java heap s ...
- 我的微信小程序第三篇(app.json)
前言 端午节回家了,所以好多天没有更新,只想说还是待在家里舒服呀,妈妈各种做好吃的,小侄子侄女各种粘着我在室外玩,导致我三天下来不仅胖了一圈,还黑了一圈,上班第一天有同事就说我晒黑了,哭~~~,为了防 ...
- Leetcode 2. Add Two Numbers(medium)
You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...
- PS调出春夏外景婚纱照
效果图 先来看看原图和夏季的效果图 先看看原图 教程终于来咯 原图暗部太深,需要将暗部提亮.可以把暗部选区选出来.为了精确选择暗部选区,我利用计算命令如上图所示.最后得到暗部的选区. 上图得到了暗部选 ...
- 有界算子p129
? 如果我把这里的1改成2,把1/(a-b) 换成1/2(a-b) 为什么不能是? 2. 这里的x是关于t的函数,为什么x属于 结果了?和x应该没有关系呀? 3. 那为什么T的范数不是一个固定值?为什 ...
- Spring AOP详细介绍
AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等待,Struts2的拦截器设计就是基于AOP的思想,是个比较经典的例子. 一 AOP的基本概念 (1)Asp ...
- 学习yii2.0——事件
参考:https://www.yiichina.com/doc/guide/2.0/concept-events 事件 yii框架中的事件定义和JavaScript中的事件定义差不多:为某个事件绑定一 ...
- 网站之robots.txt文件
一.robots.txt是什么? robots.txt是一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被搜索引擎访问的部分,或者指定搜索引擎只收录指定的内容. 当一个搜索引擎(又称搜索 ...