zoj 3689 简单背包
2013-04-20 16:31
387 查看
题意:古代某统治者要修建一些棺材,其中第 i 个棺材大小为 s[i],修建需要花费 t[i] 天,如果在剩余 x 天的时候开始修建并且能够及时完成,则能获得 x * s[i] 的报酬,总共有 T 天可用,问最大能获得的报酬为多少
#include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> using namespace std; int dp[10002]; struct node { int t,s; double ae; } aa[3005]; int cmp(struct node s,struct node t) { if(s.ae!=t.ae) return s.ae>t.ae; return s.s>t.s; } int main() { int n,T,i,j; while(scanf("%d%d",&n,&T)!=EOF) { for(i=0;i<n;i++) { scanf("%d%d",&aa[i].t,&aa[i].s); aa[i].ae=(aa[i].s*1.0)/(aa[i].t*1.0); } sort(aa,aa+n,cmp); int sum=0; memset(dp,0,sizeof(dp)); int ans=0; for(i=0;i<n;i++) { for(j=T;j>=aa[i].t;j--) { if(j-aa[i].t==0||dp[j-aa[i].t]) { dp[j]=max(dp[j],dp[j-aa[i].t]+(T-j+aa[i].t)*aa[i].s); } ans=max(ans,dp[j]); } //cout<<ans<<endl; } printf("%d\n",ans); } return 0; }
相关文章推荐
- ZOJ 3201 树形dp+背包(简单题)
- zoj 3689 Digging 贪心+01背包
- bnu 28890 &zoj 3689——Digging——————【要求物品次序的01背包】
- ZOJ 3201 简单树形背包
- zoj 2109 简单贪心背包
- zoj月赛 3689 01背包
- zoj 2014 || poj 1384 Piggy-Bank(完全背包简单变形。)
- ZOJ 3682 简单dp 背包
- Piggy-Bank(简单完全背包)
- ZOJ 3741 Eternal Reality 简单DP
- 数的乘方,简单背包,组合
- zoj 3633 map简单应用
- ZOJ-2833Friendship(简单并查集)
- 01背包问题【简单背包,UVA624】
- E - QS Network - zoj 1586(简单)
- 简单背包
- ZOJ 4508 湫湫系列故事——减肥记I(完全背包)
- 【动态规划】简单背包问题II
- Course Selection System ZOJ - 3956 【01背包变形】 好题~
- ZOJ - 3956 Course Selection System 贪心-背包思想