poj2184
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13578 | Accepted: 5503 |
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.
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int f[];
int a[],b[];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
memset(f,-,sizeof(f));
int ans=,m1=,m2=;
f[]=;
for(int i=;i<=n;i++)
{
if(a[i]>)
for(int j=;j>=a[i];j--)
{
f[j]=max(f[j],f[j-a[i]]+b[i]);
if(j->=&&f[j]>=&&j-+f[j]>ans)ans=j-+f[j];
}
if(a[i]<)
for(int j=;j<=+a[i];j++)
{
f[j]=max(f[j],f[j-a[i]]+b[i]);
if(j->=&&f[j]>=&&j-+f[j]>ans)ans=j-+f[j];
}
}
cout<<ans;
}
poj2184的更多相关文章
- POJ-2184 Cow Exhibition---01背包变形(负数偏移)
题目链接: https://vjudge.net/problem/POJ-2184 题目大意: 给出num(num<=100)头奶牛的S和F值(-1000<=S,F<=1000),要 ...
- POJ2184 Cow Exhibition[DP 状态负值]
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12420 Accepted: 4964 D ...
- poj2184 01背包变形,价值为可为负数
题目链接:http://poj.org/problem?id=2184 题意:每行给出si和fi,代表牛的两个属性,然后要求选出几头牛,满足S与F都不能为负数的条件下,使S与F的和最大. tips:动 ...
- [poj2184]我是来水一下背包的
http://poj.org/problem?id=2184 题意:01背包的变种,就是说有2组值(有负的),你要取一些物品是2阻值的和非负且最大 分析: 1.对于负的很好处理,可以把他们都加上一个数 ...
- poj2184 背包
//Accepted 1492 KB 110 ms //背包 //把si看成weight,Fi看成value,这可以表示成当dp[j]=max(dp[j-weight[i]]+value[i]) // ...
- Cow Exhibition [POJ2184] [DP] [背包的负数处理]
题意: 有很多羊,每只羊有一个幽默度和智商,要选出一些羊,智商加幽默度总和最大,其中智商总和和幽默度总和都不能是负数. 样例输入: 5 -5 7 8 -6 6 -3 2 1 -8 -5 样例输出: 8 ...
- poj2184 Cow Exhibition【01背包】+【负数处理】+(求两个变量的和最大)
题目链接:https://vjudge.net/contest/103424#problem/G 题目大意: 给出N头牛,每头牛都有智力值和幽默感,然后,这个题目最奇葩的地方是,它们居然可以是负数!! ...
- POJ-2184 Cow Exhibition(01背包变形)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10949 Accepted: 4344 Descr ...
- dp背包之01背包poj2184
http://poj.org/problem?id=2184 题意:给定两个属性,求这两个属性的和的最大值......... 思路:将第一个属性往后平移1000个单位,然后推导其动态转移方程,若是dp ...
- poj2184 Cow Exhibition(p-01背包的灵活运用)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=2184">http://poj.org/problem?id=2184 Descrip ...
随机推荐
- Eclipse 菜单---Eclipse教程第04课
Eclipse 查看的菜单栏通常包含以下几个菜单: File 菜单 Edit 菜单 Navigate 菜单 Search 菜单 Project 菜单 Run 菜单 Window 菜单 Help 菜单 ...
- Redis常用知识
1.redis是什么 redis是一种支持Key-Value等多种数据结构的存储系统.可用于缓存.事件发布或订阅.高速队列等场景.该数据库使用ANSI C语言编写,支持网络,提供字符串.哈希.列表.队 ...
- Jforum环境之Tomcat环境搭建
Jforum环境搭建,需先安装JDK.JRE.Tomcat.Mysql(JDK.JRE暂不做说明).本文先说Tomcat环境搭建 1.进入Apache Tomcat官网下载,我选择的是免安装的zip包 ...
- ASP.NET Core [3]:进入HttpContext的世界(笔记)
原文链接:http://www.cnblogs.com/RainingNight/p/httpcontext-in-asp-net-core.html HttpContext是ASP.NET中的核心对 ...
- Python全栈工程师(多继承、函数重写)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 Python人工智能从入门到精通 补充: 对象 --------- ...
- SQL 基础笔记(二):进阶查询
本笔记整理自<SQL 基础教程>.<MySQL 必知必会>和网上资料.个人笔记不保证正确. 一.复杂查询 视图 将 SELECT 查询包装成一个虚拟表,该虚拟表就被称为视图.( ...
- UVa 1445 - Cubist Artwork
统计正面看高度为i的竖条个数为cnt1[i], 统计侧面看高度为i的竖条个数为cnt2[i]: ans = sum( i * max( cnt1[i], cnt2[i] ) ); ( 1 <= ...
- 二分查找树按照key值划分
#include <iostream>#include <vector>#include <algorithm>#include <string>#in ...
- java中从实体类中取值会忽略的的问题
在我们java Map中通过get来取值时会忽略的问题是:如果取得一个空值null时,那么.toString()时就会出错,而且不知道是什么原因. 现在我给的具体方法是用条件表达式先判断一下. 例: ...
- 实用JS系列——面向对象中的类和继承
背景: 在最开始学习JavaScript时,我们就知道,它是一种脚本语言,也有面向对象机制.但它的面向对象继承机制是基于原型的,即Prototype.今天,我们就来找一下JS中OO的影子. 创建类 1 ...