ZOJ 3956 Course Selection System 01背包变形
来源:互联网 发布:建筑设计专业软件 编辑:程序博客网 时间:2024/06/06 08:43
题目链接
题意:
给你n个hi, ci,问你怎样拿才能让你 使上面式子最大。
思路:
根据上面的式子我们可知,对于一个C值当hi越大,则上面的式子才可能更大一些,又因为题目中C的值很小最多
50000,所以我们可以以C为背包容量 c[i]为体积h为价值进行01背包,然后维护一下最大值.
真的是很巧妙的问法,当时有想过dp,想到了背包可是没有明确怎么背,,,哎 orz
#include<bits/stdc++.h>#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 100000007#define inf 0x3f3f3f3fusing namespace std;typedef long long ll;const int maxn=1e5;ll dp[maxn];int n;ll h[maxn],c[maxn];int gcd(int a,int b){return b==0?a:gcd(b,a%b);}int main(){int t;Ri(t);W(t){Ri(n);CLR(dp,0);ll sum=0;for(int i=1;i<=n;i++){Rl(h[i]),Rl(c[i]);sum+=c[i];}//Pi(sum); for(int i=1;i<=n;i++){for(int j=sum;j>=c[i];j--){dp[j]=max(dp[j],dp[j-c[i]]+h[i]);}}ll ans=0;for(int i=1;i<=50000;i++){ans=max(ans,dp[i]*dp[i]-i*dp[i]-(ll)i*i);}Pl(ans);}return 0;}
1 0
- 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,01背包!
- ZOJ-3956 Course Selection System(01背包)
- zoj 3956-Course Selection System(背包)
- 浙大17年校赛(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 3956Course Selection System (01背包)
- ZOJ 3956 Course Selection System 【 思维 + 01背包 】
- zoj 3596Course Selection System(dp,01背包)
- ZOJ 3956 Course Selection System
- ZOJ 3956 Course Selection System
- zoj 3956 Course Selection System
- Spark MLlib 伪逆算法
- Redis初探06——Redis的有序集合sorted set类型及操作
- Redis集群搭建
- 用HTML做表格
- 三大数据源的流程(DBCP,C3P0,JdbcDataSource) (上)
- ZOJ 3956 Course Selection System 01背包变形
- 三大数据源的流程(DBCP,C3P0,JdbcDataSource) (下)
- Java中this关键字和super关键字的使用
- c语言实现单链表
- java获取路径
- Android中第三方SDK集成之ZXing二维码扫一扫集成指南
- tomcat报错 error parsing HTTP request header Note: further occurrences of HTTP header parsing errors
- 使用java操作FastDFS上传,下载,删除文件
- 调用支付jsapi缺少参数 total_fee