POJ2184 Cow Exhibition[DP 状态负值]
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12420 | Accepted: 4964 |
Description
fun..."
- Cows with Guns by Dana Lyons
The cows want to prove to the public that they are both smart and fun. In order to do this, Bessie has organized an exhibition that will be put on by the cows. She has given each of the N (1 <= N <= 100) cows a thorough interview and determined two values for each cow: the smartness Si (-1000 <= Si <= 1000) of the cow and the funness Fi (-1000 <= Fi <= 1000) of the cow.
Bessie must choose which cows she wants to bring to her exhibition. She believes that the total smartness TS of the group is the sum of the Si's and, likewise, the total funness TF of the group is the sum of the Fi's. Bessie wants to maximize the sum of TS and TF, but she also wants both of these values to be non-negative (since she must also show that the cows are well-rounded; a negative TS or TF would ruin this). Help Bessie maximize the sum of TS and TF without letting either of these values become negative.
Input
* Lines 2..N+1: Two space-separated integers Si and Fi, respectively the smartness and funness for each cow.
Output
Sample Input
5
-5 7
8 -6
6 -3
2 1
-8 -5
Sample Output
8
Hint
Bessie chooses cows 1, 3, and 4, giving values of TS = -5+6+2 = 3 and TF
= 7-3+1 = 5, so 3+5 = 8. Note that adding cow 2 would improve the value
of TS+TF to 10, but the new value of TF would be negative, so it is not
allowed.
Source
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=,V=N*,shift=1e5,INF=1e9;
int n,s[N],f[N],ps=,ng=,ans=;//ps+shift ng+shift
int d[V];
void dp(){
for(int i=ng+shift;i<=ps+shift;i++) d[i]=-INF;
d[shift]=;
for(int i=;i<=n;i++){//printf("i %d\n",i);
if(s[i]>=) for(int j=ps+shift;j>=s[i]+ng+shift;j--)
d[j]=max(d[j],d[j-s[i]]+f[i]);//,printf("j %d %d\n",j-shift,d[j]);
if(s[i]<) for(int j=ng+shift;j<=s[i]+ps+shift;j++)
d[j]=max(d[j],d[j-s[i]]+f[i]);//,printf("j %d %d\n",j-shift,d[j]);
}
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){scanf("%d%d",&s[i],&f[i]);if(s[i]>=) ps+=s[i];else ng+=s[i];}
dp();
for(int i=shift;i<=ps+shift;i++) if(d[i]>=) ans=max(ans,d[i]+i-shift);
cout<<ans; //cout<<"\n\n";
//cout<<ps<<" "<<ng;
}
POJ2184 Cow Exhibition[DP 状态负值]的更多相关文章
- POJ-2184 Cow Exhibition(01背包变形)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10949 Accepted: 4344 Descr ...
- poj2184 Cow Exhibition(p-01背包的灵活运用)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=2184">http://poj.org/problem?id=2184 Descrip ...
- poj2184 Cow Exhibition【01背包】+【负数处理】+(求两个变量的和最大)
题目链接:https://vjudge.net/contest/103424#problem/G 题目大意: 给出N头牛,每头牛都有智力值和幽默感,然后,这个题目最奇葩的地方是,它们居然可以是负数!! ...
- POJ 2184 Cow Exhibition (带负值的01背包)
题意:给你N(N<=100)只牛,每只牛有一个智慧值Si和一个活泼值Fi,现在要从中找出一些来,使得这些牛智慧值总和S与活泼值总和F之和最大,且F和S均为正.Si和Fi范围在-1000到1000 ...
- poj2184 Cow Exhibition
思路: dp+滚动数组. 类似01背包. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...
- POJ2184 Cow Exhibition 背包
题目大意:已知c[i]...c[n]及f[i]...f[n],现要选出一些i,使得当sum{c[i]}和sum{f[i]}均非负时,sum(c[i]+f[i])的最大值. 以sum(c[i])(c[i ...
- 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: 10882 Accepted: 4309 D ...
- POJ 2184 Cow Exhibition (01背包变形)(或者搜索)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10342 Accepted: 4048 D ...
随机推荐
- vue安装
条件:已安装 node&npm 1.安装 cnpm : $ npm install -g cnpm --registry=https://regis ...
- [实现]Javascript代码的另一种压缩与加密方法——代码图片转换
代码=图片 图片=代码 JS代码对于喜欢F12的同志来说,连个遮羞布都没有... 虽然把代码变成图片也仅仅只是增加一层纱布而已...但这方法还是挺好玩的,而且代码也被压缩了一点. 第一次看到[图片=代 ...
- React Native 常见问题集合
在使用React Native时候,我记录下比较常遇到的问题,分为以下几类: 1. 调试问题 2. 写法问题 3. 疑难问题 4. 奇怪问题 调试问题 1. 在react-native run-and ...
- Window对象
Window对象: Window 对象表示浏览器中打开的窗口,如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框 ...
- 更改SAP的字段翻译
TC:SE63在SAP用户选择屏幕中,用鼠标选定一个栏位后按F1键,可以看到SAP对其具体解释,通常这种解释文本分为两部分,一部分为标题,一部分为正文.比如: 有时,SAP的翻译让人感觉很别扭,对于 ...
- ViewPager的使用小技巧
1.在ViewPager中默认加载当前屏幕上的界面和左右相邻界面的数据从而实现页面滑动的快速切换.可以通过调用setOffscreenPageLimit(int)方法,定制预加载相邻页面的数目. 2. ...
- CocoaPods的安装和使用那些事(Xcode 7.2,iOS 9.2,Swift)
Using The CocoaPods to Manage The Third Party Open-source Libaries 介绍 CocoaPods是用来管理你的Xcode项目的依赖库的.使 ...
- Winform读写App.config文件以及重启程序
//重启主程序 //System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Locatio ...
- 使用sql server profilter跟踪sql
最近在研究EF延迟加载和贪婪加载的用法时,想要查看Linq生成的sql.一开始通过VS-->调试-->窗口-->IntelliTrace事件,来查看生成的sql,并不是十分准确.然后 ...
- MongoDB使用汇总贴
金天:学习一个新东西,就要持有拥抱的心态,如果固守在自己先前的概念体系,就会有举步维艰的感觉.应用mongodb(NoSQL)开发,首先要打破原先的关系思维.范式思维. 本文作为使用mongodb一路 ...