poj2184
来源:互联网 发布:网络语吃饼什么意思 编辑:程序博客网 时间:2024/06/05 08:55
#include <iostream>#include<cstdio>#include<algorithm>#include<math.h>#define inf -1000005using namespace std;int n,dp[100005];struct node{ int s,f;}cow[105];int cmp(node a,node b){ return a.f>b.f;}int main(){ scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&cow[i].f,&cow[i].s); sort(cow,cow+n,cmp); fill(dp,dp+100005,inf); dp[0]=0; for(int i=0;i<n;i++) { if(cow[i].f>=0) for(int j=100004;j>=0;j--) { int t=j-cow[i].f; if(t>=0&&dp[t]!=inf) dp[j]=max(dp[t]+cow[i].s,dp[j]); } else if(cow[i].f<0) { for(int j=0;j<=100004;j++) { int t=j+cow[i].f; if(t>=0&&dp[j]!=inf) dp[t]=max(dp[j]+cow[i].s,dp[t]); } } } int sum=0,flag=0; for(int j=0;j<100004;j++) { if(dp[j]>=0) { if(sum<j+dp[j]) { sum=j+dp[j]; } } } printf("%d\n",sum); return 0;}一个经典dp的变形,把二位量转化为一维
0 0
- POJ2184
- poj2184
- poj2184
- poj2184
- poj2184
- 背包 poj2184
- 【DP】poj2184
- POJ2184-Cow Exhibition
- poj2184 Cow Exhibition
- 背包问题(poj2184)
- poj2184:cow exhibition
- poj2184(01背包变形)
- poj2184 Cow Exhibition
- 【POJ2184】Cow Exhibition
- poj2184 Cow Exhibition
- poj2184解题报告
- 【poj2184】【Cow Exhibition】
- POJ2184--Cow Exhibition
- 数据库函数之 mysql date_format
- Listview优化 tag
- 总结(一) 知识点初步理解
- C#之.Net平台和编译原理简介
- 邹学勇-移动金融的流量经营
- poj2184
- Eclipse恢复默认主题
- 拥抱开源,如何关注Linux Kernel 邮件列表?
- 解决XCode6在IOS7系统上出现部分黑屏与不适配问题
- 11088 整数划分的扩展问题(递归,分治)
- poj 1904 King's Quest 强连通分量
- Exists 和 Not Exists 备忘
- OC第五课
- 李彦宏:百度用两年完成移动转型