poj2184 Cow Exhibition
思路:
dp+滚动数组。
类似01背包。
实现:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; const int INF = 0x3f3f3f3f;
const int t = ;
int a[], b[], dp[][], n, p, q;
int solve(int n)
{
for (int i = ; i < ; i++)
{
for (int j = -t; j <= t; j++)
{
dp[i][j + t] = -INF;
}
}
for (int i = ; i < ; i++)
dp[i][a[i] + t] = b[i];
for (int i = ; i < n; i++)
{
for (int j = -t; j <= t; j++)
{
dp[i & ][j + t] = max(dp[(i - ) & ][j + t], dp[i & ][j + t]);
if (j + t - a[i] < || j + t - a[i] > )
continue;
dp[i & ][j + t] = max(dp[i & ][j + t], dp[(i - ) & ][j + t - a[i]] + b[i]);
}
}
int ans = -INF;
for (int j = ; j <= t; j++)
{
ans = max(ans, dp[(n - ) & ][j + t] >= ? j + dp[(n - ) & ][j + t] : -INF);
}
return ans;
} int main()
{
cin >> n;
int cnt = ;
for (int i = ; i < n; i++)
{
cin >> p >> q;
if (p < && q < )
continue;
a[cnt] = p;
b[cnt++] = q;
}
int ans = solve(cnt);
if (ans <= -INF)
cout << "" << endl;
else
cout << ans << endl;
return ;
}
poj2184 Cow Exhibition的更多相关文章
- POJ2184 Cow Exhibition[DP 状态负值]
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12420 Accepted: 4964 D ...
- 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头牛,每头牛都有智力值和幽默感,然后,这个题目最奇葩的地方是,它们居然可以是负数!! ...
- 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(0-1背包变形)
题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total S ...
- Cow Exhibition 变种背包
Cow Exhibition Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- 广大暑假训练1(poj 2488) A Knight's Journey 解题报告
题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A (A - Children of the Candy Corn) ht ...
- 使用TextView实现跑马灯的效果
1.定义textView标签的4个属性: android:singleLine="true"//使其只能单行 android:ellipsize="marquee&quo ...
- codeforces 696B B. Puzzles(树形dp+概率)
题目链接: B. Puzzles time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- [SoapUI] Learn materials
SoapUI Training : http://soapui-tutorial.com/index.php * Below are the details to access the onlin ...
- 线段树之成段更新( 需要用到延迟标记,简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的时候)
HDU 1698 链接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直 ...
- Keepalived + HAProxy 搭建【第二篇】Keepalived 的安装与配置
第一步:准备 1. 简介 本文搭建的是利用 Keepalived 实现 HAProxy 的热备方案,即两台主机上的 HAProxy 实例同时运行,其中全总较高的实例为 MASTER,MASTER出现异 ...
- File System Programming --- (一)
About Files and Directories The file system is an important part of any operating system. After all, ...
- 在线抠图网站速抠图sukoutu.com全面技术解析之canvas应用
技术关键词 Canvas应用,泛洪算法(Flood Fill),图片缩放,相对位置等比缩放,判断一个点是否在一个平面闭合多边形,nginx代理 业务关键词 在线抠图,智能抠图,一键抠图,钢笔抠图,矩阵 ...
- E20180420-hm
prior adj. 优先的; 占先的; 在…之前 alignment n. 结盟; 队列,排成直线; 校直,调整; [工] 准线; align vt. 使成一线,使结盟; 排整齐 vi. 排 ...
- J20170507-ts
プロンプト n. 提示 オブジェクト n. 对象 アスタリスク * アンパサンド & スラッシュ / イテレータ n 迭代器 差し詰め 当前 スペル spell ...