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 ...
随机推荐
- 计算机学院大学生程序设计竞赛(2015’12)Happy Value
Happy Value Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 一步一步学Silverlight 2系列(13):数据与通信之WebRequest
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- BZOJ_4278_[ONTAK2015]Tasowanie_后缀数组
BZOJ_4278_[ONTAK2015]Tasowanie_后缀数组 Description 给定两个数字串A和B,通过将A和B进行二路归并得到一个新的数字串T,请找到字典序最小的T. Input ...
- Spring之配置文件加载方式
spring在org.springframework.core.io包中提供了多种配置文件加载方式.无论是XML.URL还是文件,都有很好的支持.比如基于URL的UrlResource.基于输入流的I ...
- emacs编辑c文件时,大括号的跳转(转载)
转自:http://forum.ubuntu.org.cn/viewtopic.php?f=68&t=26701 `C-M-n' Move forward over a parenthetic ...
- A tutorial by example(转载)
转自:http://mrbook.org/blog/tutorials/make/ Compiling your source code files can be tedious, specially ...
- Oracle Function INSTR
INSTR(string,subString,position,ocurrence)查找字符串位置 解释: string:字符串 subString:要查找的子字符串 p ...
- Thirft 客户端等待时间
thrift框架使用C++ thrift shows CLOSE_WAIL error thrift中TNonblockingServer的简单用法
- SDUT2161:Simple Game(NIM博弈+巴什博弈)
传送门 题意 n堆石子,每次可以取一堆至三堆任意非零石子数,取完者赢,问最后谁能赢 分析 以前我们做过NIM博弈是对一堆进行操作,现在换成了三堆,其实对于n堆都一样一堆的情况 如果最后二进制每位数的1 ...
- HDOJ1864(水的可怜)
注意这句话:精确到小数点后两位如果是小数点的话 HDOJ1864 #include<stdio.h> #include<iostream> #include<algori ...