浙大校赛 ZOJ 3956Course Selection System (01背包)
来源:互联网 发布:道光知乎 编辑:程序博客网 时间:2024/06/06 05:32
题意:给定n件物品,每件物品有2个值H和C,求选取一些物品使的值最大
思路:C的范围比较小,求C的总和sum,然后作为背包容量,求出和为1~sum时H的和的最大值,最后求下要求式子的最大值。
比赛时一直想着贪心,按H-C从大到小拍下序,一直wa
code:
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;const int maxn=510;typedef long long ll;ll h[maxn],c[maxn],dp[100*maxn];int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); ll ans=0,sum=0; for(int i=0; i<n; i++) { scanf("%lld%lld",&h[i],&c[i]); sum+=c[i]; } memset(dp,0,sizeof(dp)); for(int i=0; i<n; i++) { for(ll j=sum;j>=c[i];j--) { dp[j]=max(dp[j-c[i]]+h[i],dp[j]); } } for(ll i=1;i<=sum;i++) { ans=max(ans,dp[i]*dp[i]-dp[i]*i-i*i); } printf("%lld\n",ans); }}
0 0
- 浙大校赛 ZOJ 3956Course Selection System (01背包)
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- 浙大17年校赛(ZOJ 3956)Course Selection System[01背包]
- 2017 浙大校赛 Course Selection System(01背包)
- ZOJ 3956 Course Selection System 01背包
- Zoj 3956 Course Selection System【01背包】
- ZOJ 3956 Course Selection System 01背包
- ZOJ-3956 Course Selection System,01背包!
- ZOJ-3956 Course Selection System(01背包)
- zoj 3956-Course Selection System(背包)
- ZOJ 3956 Course Selection System(01背包)
- Zoj 3956 Course Selection System (01背包)
- ZOJ 3956 Course Selection System 01背包变形
- ZOJ 3956 Course Selection System (dp 01背包)
- ZOJ 3956 Course Selection System(01背包变形)
- ZOJ 3956 Course Selection System 【 思维 + 01背包 】
- 浙大校赛- Course Selection System
- Twitter Lite以及大规模的高性能React渐进式网络应用
- LintCode 29 交叉字符串
- 【error】VS2010 LINK1123: failure during conversion to COFF: file invalid or corrupt
- 调停者模式(Mediator Pattern,对象行为型模式,中介者模式)
- android自适应屏幕
- 浙大校赛 ZOJ 3956Course Selection System (01背包)
- nginx架构(三)Nginx服务器的代理服务
- 递推递归练习M
- 24段魔尺--小海龟图案
- 动态规划练习一 24:鸣人的影分身
- 10023---linux查看及修改文件权限以及相关
- The first girlfriend -- AngularJS
- 13:最大上升子序列和
- HashMap实现原理