Cow Exhibition [POJ2184] [DP] [背包的负数处理]
题意:
有很多羊,每只羊有一个幽默度和智商,要选出一些羊,智商加幽默度总和最大,其中智商总和和幽默度总和都不能是负数。
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b) for(RG i=a;i<=b;++i)
#define per(i,a,b) for(RG i=a;i>=b;--i)
#define ll long long
#define inf (1<<29)
#define O 100000
#define maxn 105
#define maxm 200005
using namespace std;
int n;
int dp[maxm],v[maxn],w[maxn];
inline int read()
{
int x=,f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int main()
{
n=read();
rep(i,,n) w[i]=read(),v[i]=read();
//memset(dp,-63,sizeof(dp));
dp[O]=;
rep(i,,n)
{
if(v[i]>=)
per(j,maxm-,v[i])
dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
else
rep(j,,maxm-+v[i])
dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
}
int ans=;
rep(i,O,maxm-)
if(dp[i]>=)
ans=max(ans,dp[i]+i-O);
cout<<ans;
return ;
}
Cow Exhibition [POJ2184] [DP] [背包的负数处理]的更多相关文章
- 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 ...
- poj2184 Cow Exhibition【01背包】+【负数处理】+(求两个变量的和最大)
题目链接:https://vjudge.net/contest/103424#problem/G 题目大意: 给出N头牛,每头牛都有智力值和幽默感,然后,这个题目最奇葩的地方是,它们居然可以是负数!! ...
- poj 2184 Cow Exhibition(dp之01背包变形)
Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - ...
- poj2184 Cow Exhibition(p-01背包的灵活运用)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=2184">http://poj.org/problem?id=2184 Descrip ...
- POJ 2184:Cow Exhibition(01背包变形)
题意:有n个奶牛,每个奶牛有一个smart值和一个fun值,可能为正也可能为负,要求选出n只奶牛使他们smart值的和s与fun值得和f都非负,且s+f值要求最大. 分析: 一道很好的背包DP题,我们 ...
- Cow Exhibition (01背包)
"Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with G ...
- PKU--2184 Cow Exhibition (01背包)
题目http://poj.org/problem?id=2184 分析:给定N头牛,每头牛都有各自的Si和Fi 从这N头牛选出一定的数目,使得这些牛的 Si和Fi之和TS和TF都有TS>=0 F ...
- POJ-2184 Cow Exhibition(01背包变形)
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10949 Accepted: 4344 Descr ...
随机推荐
- Docker常见命令
docker制作Images docker build -t 镜像名 .(“.”最后这一个点不能忽略) docker 运行Images docker run --name=容器名 --net=host ...
- Tensorflow name_scope
在 Tensorflow 当中有两种途径生成变量 variable, 一种是 tf.get_variable(), 另一种是 tf.Variable(). 使用tf.get_variable()定义的 ...
- SPOJ 1812 LCS2
题解: 和上一题差不多 每个点记录前面的到这个点的最大值 初值赋为len[i] 然后注意要用子节点更新父节点 代码: #include <bits/stdc++.h> #define ll ...
- 3步实现ssh面密码登录
1.上次本机的公钥和私钥 [root@vicweb ~]#ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in ...
- MySQL事务提交过程(一)
MySQL作为一种关系型数据库,已被广泛应用到互联网中的诸多项目中.今天我们来讨论下事务的提交过程. MySQL体系结构 由于mysql插件式存储架构,导致开启binlog后,事务提交实质是二阶段提交 ...
- 解决 Ionic 浏览器跨域问题
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...
- Linux 常用基本指令
1.ls 参数: -a:列出所有目录(“.”开头的是隐藏文件) -l: 以长格式列出目录下的内容列表 2.cd cd 切换到家目录 cd ~ 切换到家目录 cd .. 切换到上一级目录 3.pwd ...
- Flume的概述和安装部署
一.Flume概述 Flume是一种分布式.可靠且可用的服务,用于有效的收集.聚合和移动大量日志文件数据.Flume具有基于流数据流的简单灵活的框架,具有可靠的可靠性机制和许多故障转移和恢复机制,具有 ...
- goLand工程结构管理
goLand工程结构管理 转 https://www.jianshu.com/p/eb7b1fd7179e 开始之前请确保安装好了 go语言环境并配置好了gopath环境变量 1.创建一个新目录并打 ...
- Windows10 下Apache服务器搭建
Windows10 下Apache服务器搭建 转 https://blog.csdn.net/sunqian666888/article/details/78561399 目录 一.软件下载 二. ...