poj3186 poj3267
两道很不错的dp
3186很神似回文词,合并石子之类的问题;
一开始不知道怎么在dp方程中体现权值天数,很来才想起来
对于一段区间[i,j],里面的东西必然是要卖完的
又因为只能从两头开始卖,所以
dp[i,j]=max(dp[i+1,j],dp[i,j-1])+sum[i,j];
这样就体现出先后卖的差别;
最后答案很显然是dp[1,n];
而poj3267,dp方程不好讲,直接上代码;
var f:array[..,..] of longint;
b,a,sa,sb:array[..] of longint;
p,y,q,i,j,k,n,m:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; begin
readln(m,n);
for i:= to n do
begin
readln(b[i],a[i]);
sa[i]:=sa[i-]+a[i];
sb[i]:=sb[i-]+b[i];
end;
f[,]:=;
i:=;
while i<=*n+ do
begin
inc(i);
f[i,]:=f[i-,];
for j:= to n do
begin
if f[i-,j]= then break;
f[i,]:=max(f[i,],f[i-,j]);
end;
for j:= to n do
begin
for k:= to n do
begin
if (f[i-,k]=) and (k<>) then break; //后面的状态不存在,直接退
p:=f[i-,k];
q:=f[i-,k]+j;
if q>n then continue;
y:=f[i-,k]-k;
if (sb[q]-sb[p]+sa[p]-sa[y]<=m) and (sa[q]-sa[p]<=m) then //判断是否够这个月花的
f[i,j]:=max(f[i,j],f[i-,k]+j);
end;
if f[i,j]>=n then
begin
writeln(i+); //注意付完款一定是下个月
halt;
end;
if f[i,j]= then break;
end;
end;
end.
poj3186 poj3267的更多相关文章
- POJ3267——The Cow Lexicon(动态规划)
		The Cow Lexicon DescriptionFew know that the cows have their own dictionary with W (1 ≤ W ≤ 600) wor ... 
- POJ-3267 The Cow Lexicon---删除字符匹配单词
		题目链接: https://cn.vjudge.net/problem/POJ-3267 题目大意: 题意就是给出一个主串,和一本字典,问最少在主串删除多少字母,可以使其匹配到字典的单词序列. PS: ... 
- poj3186 Treats for the Cows(区间)
		题目链接:http://poj.org/problem?id=3186 题意:第一个数是N,接下来N个数,每次只能从队列的首或者尾取出元素. ans=每次取出的值*出列的序号.求ans的最大值. 样例 ... 
- POJ3267 The Cow Lexicon(DP+删词)
		The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9041 Accepted: 4293 D ... 
- POJ3186:Treats for the Cows(区间DP)
		Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for gi ... 
- poj3186                              Treats for the Cows
		http://poj.org/problem?id=3186 Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total S ... 
- POJ3267 The Cow Lexicon(dp)
		题目链接. 分析: dp[i]表示母串从第i位起始的后缀所对应的最少去掉字母数. dp[i] = min(dp[i+res]+res-strlen(pa[j])); 其中res 为从第 i 位开始匹配 ... 
- POJ3186(KB12-O DP)
		Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5801 Accepted: 30 ... 
- POJ3267
		从今天开始POJ里的一部分类型的题目就一般不放在一起写了 一个是太丑,格式麻烦,第二个是以后的题目难度都有所增大,因此一道题可能就要写蛮长 尤其是DP这一块,以前一直没好好学习,现在从基础的先开始吧 ... 
随机推荐
- soinn
			Growing Cell Structures A Self-Organizing Network for Unsupervised and Supervised Learning Here, and ... 
- 让Ecshop网店系统用户自动登陆
			让Ecshop网店系统用户户自动登陆,打开ecshop includes/init.php文件,可以发现Ecshop系统判断用户的SESSION不存在的时候会去读取存储在COOKIES里面的值.如下代 ... 
- s3c-u-boot-1.1.6源码分析
			源码 源码结构 移植准备 
- 一、记一次失败的 CAS 搭建 之 环境配置
			==================================================================================================== ... 
- 【IOCP】  IOCP模型属于一种通讯模型- 较难
			http://baike.baidu.com/link?url=e9vXkKd2aHp8VDr1XTURdwQB4K85r28IYjeMwRIyuaXtsrCsXHY1eohiFgsDXRYRlj6x ... 
- .net google calendar
			https://developers.google.com/gdata/client-cs http://www.codeproject.com/Articles/64474/How-to-Read- ... 
- Nhibernate 多对多级联删除
			在网上找到的方法:查看这里 //-------------------------------------Article.hbm.xml-------------------------------- ... 
- unity手游之聊天SDK集成与使用一
			手游中都有聊天功能,比如公会,私聊,世界聊天,那么找一个好用,功能强大的SDK的可以节省很多精力,帮助我们提高开发速度与游戏质量. 写本篇博文是为了方便使用这个SDK做聊天模块的程序,避免许多坑,我在 ... 
- poj 2762 Going from u to v or from v to u?(强连通分量+缩点重构图+拓扑排序)
			http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS Memory Limit: ... 
- failed to lazily initialize a collection of role
			可能修复了一个重大的偶尔发生的几乎难以察觉的并且到现在我也没能理解的bug...有时(经常)调用updateNotNullfield方法(原理是从数据库中get一个对象,然后把原对象中非空的值赋予它, ... 
