用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的更多相关文章

  1. 【LeetCode】273. Integer to English Words

    Integer to English Words Convert a non-negative integer to its english words representation. Given i ...

  2. leetcode@ [273] Integer to English Words (String & Math)

    https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to its englis ...

  3. Integer to English Words 解答

    Question Convert a non-negative integer to its english words representation. Given input is guarante ...

  4. LeetCode Integer to English Words

    原题链接在这里:https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to it ...

  5. 273 Integer to English Words 整数转换英文表示

    将非负整数转换为其对应的英文表示,给定的输入是保证小于 231 - 1 的.示例:123 -> "One Hundred Twenty Three"12345 -> & ...

  6. LeetCode 273. Integer to English Words

    原题链接在这里:https://leetcode.com/problems/integer-to-english-words/description/ 题目: Convert a non-negati ...

  7. words

    conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...

  8. 使用千位分隔符(逗号)表示web网页中的大数字

    做手机端页面我们常常遇到数字,而在Safari浏览器下这些数字会默认显示电话号码,于是我们就用到了补坑的方法加入<meta>标签: <meta name="format-d ...

  9. HDU 4169 树形DP

    Wealthy Family Problem Description While studying the history of royal families, you want to know ho ...

  10. How to Pronounce Numbers 20 – 1 Billion

    How to Pronounce Numbers 20 – 1 Billion Share Tweet Share Tagged With: Numbers Numbers are something ...

随机推荐

  1. 编剧小记 — Contour

    前言 Contour 是一款比较优秀的编剧辅助软件,按理说这篇文章应该归类到mac小记中,但其操作非常简单,基本上以写作提示为主.只怪所有提示都是英语,而且很多,每次使用打开 Contour 个别单词 ...

  2. 牛客---java练习

    一. 1. abstract可以修饰方法和类,不能修饰属性.抽象方法没有方法体,即没有大括号{}.抽象类中的成员属性都是public static final类型的:成员方法都是public abst ...

  3. 三次握手复习TCP

    临近下班,突然想起三次握手的概念有点模糊. 大学时候的<计算机网络>是英语版的,那时候学习迷迷糊糊的.大概记得一个模型罢了. 幸好,大学基本所有的书都卖了,就是计算机网络没卖.待会回去看看 ...

  4. React Native之code-push的热更新(ios android)

    React Native之code-push的热更新(ios android) React Native支持大家用React Native技术开发APP,并打包生成一个APP.在动态更新方面React ...

  5. React-Native之轮播组件looped-carousel的介绍与使用

    React-Native之轮播组件looped-carousel的介绍与使用 一,关于react-native轮播组件的介绍与对比 1,react-native-swiper在动态使用网页图片,多张图 ...

  6. spark、standalone集群 (1)

    1.配置 spark/apache/org 下载解压, 安装jdk1.8 2.准备服务器 3.设置hostname 4.关闭防火墙 开启: service iptables start 关闭: ser ...

  7. 谷歌浏览器报错 Active resource loading counts reached to a per-frame

    Active resource loading counts reached to a per-frame limit while the tab is in background. Network ...

  8. servlet ServletContext

    一.Servlet简介 1.什么是Servlet Servlet 运行在服务端的Java小程序,是sun公司提供一套规范(接口),用来处理客户端请求.响应给浏览器的动态资源.但servlet的实质就是 ...

  9. javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.

    项目依赖 <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifa ...

  10. Day 5-4封装.__隐藏属性或者方法

    封装 property 封装,也就是把客观事物封装成抽象的类,并且类可以把自己的数据和方法只让可信的类或者对象操作,对不可信的进行信息隐藏. 在python中用双下划线开头的方式将属性隐藏起来(设置成 ...