POJ Cow Exhibition
题目链接:Click Here~
题目意思自己看吧。
算法分析:
对我来想是没有想到,最后看别人的博客才知道的。要把当中的一个条件当作体积。由于两个条件都存在负数,所以还要先保证最后不会再体积中出现负数的情况。这个easy想到就是给其加上一个题目负数的上限就好了。还有的就是当中的正负出现会影响计算时候的正逆顺序。细节自己看吧。我也不太懂得讲。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std; const int MAXN = 200005;
const int INF = ~0U >> 2;
int dp[MAXN],s[105],f[105];
int main()
{
int n;
while(~scanf("%d",&n))
{
int V = 100000;
for(int i = 0;i < n;++i)
scanf("%d%d",&s[i],&f[i]);
for(int i = 0;i < MAXN;++i)
dp[i] = -INF;
dp[V] = 0;
int maxv,minv;
maxv = minv = V;
for(int i = 0;i < n;++i){
if(s[i] > 0)
for(int j = maxv;j >= minv;--j)
dp[j+s[i]] = max(dp[j+s[i]],dp[j]+f[i]);
else
for(int j = minv;j <= maxv;++j)
dp[j+s[i]] = max(dp[j+s[i]],dp[j]+f[i]);
}
int ans = 0;
for(int i = V;i <= maxv;++i){
if(dp[i] >= 0) ans = max(ans,dp[i]+i-V);
}
printf("%d\n",ans);
}
return 0;
}
POJ Cow Exhibition的更多相关文章
- [POJ 2184]--Cow Exhibition(0-1背包变形)
题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2184 Cow Exhibition【01背包+负数(经典)】
POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...
- POJ 2184 Cow Exhibition (01背包变形)(或者搜索)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10342 Accepted: 4048 D ...
- poj 2184 Cow Exhibition(01背包)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10882 Accepted: 4309 D ...
- POJ2184 Cow Exhibition[DP 状态负值]
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12420 Accepted: 4964 D ...
- Cow Exhibition 变种背包
Cow Exhibition Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ-2184 Cow Exhibition(01背包变形)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10949 Accepted: 4344 Descr ...
- (01背包变形) Cow Exhibition (poj 2184)
http://poj.org/problem?id=2184 Description "Fat and docile, big and dumb, they look so stupid ...
- poj 2184 Cow Exhibition(dp之01背包变形)
Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - ...
随机推荐
- [ nginx ] 代理后端tomcat 无法显示图片报错:ERR_CONTENT_LENGTH_MISMATCH
问题日志如下:
- html中的定位与层级设置
#转载请先留言联系 定位 HTML中的position属性可以对元素进行定位,通过position的不同的值,可以配合方位属性,让元素显示页面中的任何一个位置. position有四个值: stati ...
- 解决使用base64解码太慢的问题,原因是根本就不应该使用此方法解决。
/* 功能:将中文内容的斜杠和双引号转了,方便保存到lua+ssdb中,从SSDB提取出来组装JSON时就不会出错. 作者:黄海 时间:2015-01-31 */ function jsonencod ...
- 移动APP 支付宝快捷支付开发流程
[代码] [Java]代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...
- python的垃圾回收机制和析构函数__del__
析构函数__del__定义:在类里定义,如果不定义,Python 会在后台提供默认析构函数. 析构函数__del__调用: A.使用del 显式的调用析构函数删除对象时:del对象名: class F ...
- 区间DP【p4290】[HAOI2008]玩具取名
Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用"WING"中 ...
- cogs 服务点设置
3. 服务点设置 ☆ 输入文件:djsa.in 输出文件:djsa.out 简单对比时间限制:1 s 内存限制:128 MB 问题描述为了进一步普及九年义务教育,政府要在某乡镇建立一所 ...
- HYSBZ - 2038 小Z的袜子 (莫队算法)
A1206. 小Z的袜子 时间限制:1.0s 内存限制:512.0MB 总提交次数:744 AC次数:210 平均分:44.44 将本题分享到: 查看未格式化的试题 ...
- RPD Volume 168 Issue 4 March 2016 评论5
Monte Carlo simulation of secondary radiation exposure from high-energy photon therapy using an anth ...
- [BZOJ 2115] Xor
Link:https://www.lydsy.com/JudgeOnline/problem.php?id=2115 Algorithm: 此题一看到是求异或和最大问题的,立即想到使用线性基解题 最终 ...