zoj 3077 Move to Baggage Office(离散化处理+背包dp)
来源:互联网 发布:知乎 江歌 贫困生 编辑:程序博客网 时间:2024/05/12 06:46
【题目大意】:一个人有能量s,现在有n件物品,每件物品有价值v,现在把这件物品要消耗能量x,搬完这件物品能回复能量y。问最多可以搬动多少物品。
【解题思路】:背包是明显的....但是也是明显错误的...因为我可能拿了A之后拿不了B,但是拿了B之后却可以拿A....所以需要用离散化来消除这种后效性...
不知道排哪个序啊...一个一个的试,然后试到了拿y从大到小排时AC了....-_-!!!!!!....
其实因为题目有一个条件x>y。。我很愿意把它理解成每次我都是希望它恢复的能力越多越好...
【代码】:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include <cmath>#include <string>#include <cctype>#include <map>#include <iomanip> using namespace std; #define eps 1e-8#define pi acos(-1.0)#define inf 1<<30#define linf 1LL<<60#define pb push_back#define lc(x) (x << 1)#define rc(x) (x << 1 | 1)#define lowbit(x) (x & (-x))#define ll long longstruct Node{ int v,x,y;}a[110];int dp[1100];int s,n;bool cmp(const Node &a,const Node &b){ return a.y>b.y;}int main() { int T; cin >> T; while (T--){ scanf("%d%d",&s,&n); for (int i=0; i<n; i++){ scanf("%d%d%d",&a[i].v,&a[i].x,&a[i].y); } sort(a,a+n,cmp); memset(dp,0,sizeof(dp)); for (int j=0; j<n; j++){ for (int i=0; i<=s+a[j].y-a[j].x; i++){ if (i-a[j].y>=0) dp[i]=max(dp[i],dp[i+a[j].x-a[j].y]+a[j].v); } } int ans=-1; for (int i=0; i<=s; i++) { if (dp[i]>ans) ans=dp[i]; } printf("%d\n",ans); } return 0;}
- zoj 3077 Move to Baggage Office(离散化处理+背包dp)
- ZOJ 2972(背包dp)
- poj1170shopping office(DP背包问题)
- LuoguP1052[NOIP2005] 过河 解题报告【离散化+背包型DP】
- Zoj 3581 离散化
- zoj 3790 离散化
- ZOJ 3682 简单dp 背包
- srm 308 div2 1000(DP, 离散背包+连续背包)
- hdu3666 离散化dp
- Millionare_离散化&&DP
- zoj 3349 Special Subsequence 【离散化二分 + 线段树优化dp】
- ZOJ-3264 Present for MM (背包dp)
- 坐标离散化处理
- 离散化处理
- 【dp+离散化】hdu 4028
- hdu5009 离散化+dp+优化
- hdu 5009 dp+离散化
- POJ3666 离散化的dp
- 高仿launcher和墨迹左右拖动效果
- 哈希排序
- android中listview分页加载数据
- POJ-1067 取石子游戏 解题报告
- a new start, again
- zoj 3077 Move to Baggage Office(离散化处理+背包dp)
- 解决bug:The content of the adapter has changed but ListView did not receive a notification
- VB.NET 给DataGrid加上右键菜单
- java调用matlab代码方法[matlab version 2010a]
- PXE及PXE启动
- libsvm在64位linux下matlab编译
- 信号丢失问题
- POJ-1977 很好的矩阵乘法题..
- C/C++中指针和引用之相关问题研究