# poj 2184 Cow Exhibition

267人阅读 评论(0)

#include <cstdio>
#include <algorithm>
#include <memory.h>
using namespace std;

const int maxs = 200000 + 2000;
const int maxn = 100 + 10;
const int INF = -9999999;
const int ORI = 100000;

int n, top, down, smart[maxn], fun[maxn], dp[maxs];

void solve()
{
memset(dp, INF, sizeof(dp));
dp[ORI] = 0;
int r = ORI + top, l = ORI + down;
for (int i = 1; i <= n; ++i) {
if (smart[i] >= 0)
for (int j = r; j >= l; --j)
dp[j] = max(dp[j-smart[i]] + fun[i], dp[j]);
else
for (int j = l; j <= r; ++j)
dp[j] = max(dp[j-smart[i]] + fun[i], dp[j]);
}
}

void output()
{
int tf_ts = 0;
for (int i = ORI; i <= ORI + top; ++i)
if (dp[i] >= 0)
tf_ts = max(tf_ts, dp[i] + i - ORI);
printf("%d\n", tf_ts);
}

int main()
{
scanf("%d", &n);
top = 0; down = 0;
for (int i = 1; i <= n; ++i)
{
scanf("%d %d", &smart[i], &fun[i]);
if (smart[i] > 0)
top += smart[i];
else
down += smart[i];
}
solve();
output();
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：22400次
• 积分：634
• 等级：
• 排名：千里之外
• 原创：42篇
• 转载：8篇
• 译文：0篇
• 评论：0条
评论排行