题目链接:Click Here~

题目意思自己看吧。

算法分析:

对我来想是没有想到,最后看别人的博客才知道的。要把当中的一个条件当作体积。由于两个条件都存在负数,所以还要先保证最后不会再体积中出现负数的情况。这个easy想到就是给其加上一个题目负数的上限就好了。还有的就是当中的正负出现会影响计算时候的正逆顺序。细节自己看吧。我也不太懂得讲。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std; const int MAXN = 200005;
const int INF = ~0U >> 2;
int dp[MAXN],s[105],f[105];
int main()
{
int n;
while(~scanf("%d",&n))
{
int V = 100000;
for(int i = 0;i < n;++i)
scanf("%d%d",&s[i],&f[i]);
for(int i = 0;i < MAXN;++i)
dp[i] = -INF;
dp[V] = 0;
int maxv,minv;
maxv = minv = V;
for(int i = 0;i < n;++i){
if(s[i] > 0)
for(int j = maxv;j >= minv;--j)
dp[j+s[i]] = max(dp[j+s[i]],dp[j]+f[i]);
else
for(int j = minv;j <= maxv;++j)
dp[j+s[i]] = max(dp[j+s[i]],dp[j]+f[i]);
}
int ans = 0;
for(int i = V;i <= maxv;++i){
if(dp[i] >= 0) ans = max(ans,dp[i]+i-V);
}
printf("%d\n",ans);
}
return 0;
}

POJ Cow Exhibition的更多相关文章

  1. [POJ 2184]--Cow Exhibition(0-1背包变形)

    题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  2. POJ 2184 Cow Exhibition【01背包+负数(经典)】

    POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...

  3. POJ 2184 Cow Exhibition (01背包变形)(或者搜索)

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10342   Accepted: 4048 D ...

  4. poj 2184 Cow Exhibition(01背包)

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10882   Accepted: 4309 D ...

  5. POJ2184 Cow Exhibition[DP 状态负值]

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12420   Accepted: 4964 D ...

  6. Cow Exhibition 变种背包

    Cow Exhibition Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  7. POJ-2184 Cow Exhibition(01背包变形)

    Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10949 Accepted: 4344 Descr ...

  8. (01背包变形) Cow Exhibition (poj 2184)

    http://poj.org/problem?id=2184   Description "Fat and docile, big and dumb, they look so stupid ...

  9. poj 2184 Cow Exhibition(dp之01背包变形)

    Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - ...

随机推荐

  1. 项目问题整理(it)

    1,很(屎)优(一)雅(样)的IE9兼容问题: --webuploader在webkit浏览器中自动使用h5上传,但在IE中需要配置支持flash,特别注意两点: ①Upload.swf路径问题不正确 ...

  2. C#获取屏幕大小或任务栏大小

    C#获取屏幕大小或任务栏大小http://www.cnblogs.com/chlyzone/archive/2012/11/05/2754601.html

  3. 使用厂商MIB库查找设备OID值 并实施监控的方法

    http://chuansong.me/n/2700132 https://wenku.baidu.com/view/eeaeb1d680eb6294dd886cc7.html

  4. 关于mysql数据库的表概况 ,查看表状态

    SHOW TABLE STATUS FROM `DB_NAME` WHERE  ENGINE IS NOT NULL; SHOW TABLE STATUS FROM `DB_NAME`  WHERE ...

  5. 浅谈C#多线程与UI响应

    www.educity.cn     发布者:shenywww                    来源:网络转载                     发布日期:2014年10月06日      ...

  6. 建立新的acticity需要的注意的问题

    首先需要我们在mainifests中进行注册, <activity android:name="com.special.residemenudemo.CameraActivity&qu ...

  7. Codeforces Round #404 (Div. 2) E. Anton and Permutation(树状数组套主席树 求出指定数的排名)

    E. Anton and Permutation time limit per test 4 seconds memory limit per test 512 megabytes input sta ...

  8. HDOJ 5009 Paint Pearls

    Dicripntion Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans t ...

  9. 【动态规划】Gym - 100507G - The Debut Album

    一般思路的dp是用f(i,j,0)表示前i位最后有j个1的方案数,用f(i,j,1)表示前j位最后有j个2的方案数,j都是大于等于1的,然后比较容易转移. 但这题卡内存,就只能用f(i,j)表示前i位 ...

  10. 【博弈论】【SG函数】bzoj1457 棋盘游戏

    一开始就必胜的特判一下. #include<cstdio> #include<cstring> #include<set> #include<algorith ...