|BZOJ 1649|二维背包|[Usaco2006 Dec]Cow Roller Coaster
来源:互联网 发布:课时统计软件app 编辑:程序博客网 时间:2024/05/16 19:42
BZOJ 1649
Luogu 2854
from: USACO 2006 Dec Sliver(USACO刷题第10题)
显然是二维费用01背包。
但是直接做会超时,而且还有连接的限制。
根据题意可以知道只有在
那么我们设
那么有下列转移方程
同时,这样使用会有后效性,我们将数组按照
注意,方程初始化全部为
#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<vector>#define ms(i, j) memset(i, j, sizeof i)#define LL long longusing namespace std;const int MAXN = 10000 + 5, MAXL = 1000 + 5;struct data { int xi, wi, fi, ci; bool operator < (const data &b) const { return xi < b.xi; }}di[MAXN];int L, n, B;LL f[MAXL][MAXL];//设f[i][j]为铺到i,成本为j void clear() { ms(f, -127); f[0][0] = 0;}void init() { clear(); for (int i=1;i<=n;i++) { scanf("%d%d%d%d", &di[i].xi, &di[i].wi, &di[i].fi, &di[i].ci); } sort(di+1, di+1+n);}void solve() { LL ans = 0; for (int i=1;i<=n;i++) { for (int j=B;j>=di[i].ci;j--) { f[di[i].xi+di[i].wi][j] = max(f[di[i].xi+di[i].wi][j], f[di[i].xi][j-di[i].ci]+di[i].fi); ans = max(ans, f[L][j]); } } if (ans>0) printf("%lld\n", ans); else printf("-1\n");}int main() { #ifndef ONLINE_JUDGE freopen("1.in", "r", stdin);freopen("1.out", "w", stdout); #endif while (scanf("%d%d%d", &L, &n, &B)==3) init(), solve(); return 0;}
阅读全文
0 0
- |BZOJ 1649|二维背包|[Usaco2006 Dec]Cow Roller Coaster
- bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster 背包dp
- BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster
- bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster(DP)
- 1649: [Usaco2006 Dec]Cow Roller Coaster
- 【BZOJ1649】[Usaco2006 Dec]Cow Roller Coaster【背包DP】
- BZOJ1649: [Usaco2006 Dec]Cow Roller Coaster 背包DP
- bzoj1649 [Usaco2006 Dec]Cow Roller Coaster
- bzoj1649: [Usaco2006 Dec]Cow Roller Coaster
- BZOJ1649: [Usaco2006 Dec]Cow Roller Coaster
- poj 3257 Cow Roller Coaster(二维背包)
- POJ - 3257 Cow Roller Coaster (背包)
- POJ-3257-Cow Roller Coaster
- dp专辑 L - Cow Roller Coaster
- poj3257(Cow Roller Coaster)DP
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
- |BZOJ 1648|DFS|[Usaco2006 Dec]Cow Picnic 奶牛野餐
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 题解
- 2017.05.27【提高组】模拟赛B组
- 浏览器加载网络图片
- 关于jQuery的小项目
- 人民币冠字号码识别
- 题目1012:畅通工程(浙大)
- |BZOJ 1649|二维背包|[Usaco2006 Dec]Cow Roller Coaster
- request中getParameter和getAttribute的区别
- gridview绑定linqdatasource后获取gridview中的字段
- Windows 10 关闭系统自动更新
- MySQL+DRBD+heartbeat高可用方案
- 第三节 JDBC批处理文件(一)
- [bzoj1295]: [SCOI2009]最长距离
- JavaScript小功能
- nohup 用法