【BZOJ1649】[Usaco2006 Dec]Cow Roller Coaster【背包DP】

原创 2016年05月31日 18:06:20

【题目链接】

设dp[i][j],表示前i个位置,花费为j,的最大有趣指数。

然后类似背包一样转移。

/* Telekinetic Forest Guard */
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 1005, maxm = 10005;

int L, n, m, dp[maxn][maxn];

struct _data {
	int l, r, w, c;

	bool operator < (const _data &x) const {
		return l < x.l;
	}
} track[maxm];

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return f * x;
}

int main() {
	L = iread(); n = iread(); m = iread();
	for(int i = 1; i <= n; i++) track[i].l = iread(), track[i].r = track[i].l + iread(), track[i].w = iread(), track[i].c = iread();
	sort(track + 1, track + 1 + n);
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++)
		for(int j = track[i].c; j <= m; j++) if(~dp[track[i].l][j - track[i].c])
			dp[track[i].r][j] = max(dp[track[i].r][j], dp[track[i].l][j - track[i].c] + track[i].w);
	int ans = -1;
	for(int i = 1; i <= m; i++) ans = max(ans, dp[L][i]);
	printf("%d\n", ans);
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

bzoj1649 [Usaco2006 Dec]Cow Roller Coaster

Description The cows are building a roller coaster! They want your help to design as fun a roller...
  • zhb1997
  • zhb1997
  • 2014年07月31日 21:16
  • 508

bzoj1649: [Usaco2006 Dec]Cow Roller Coaster

1649: [Usaco2006 Dec]Cow Roller Coaster Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 472  Solved...

BZOJ1649: [Usaco2006 Dec]Cow Roller Coaster 背包DP

1649: [Usaco2006 Dec]Cow Roller Coaster Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 584  So...
  • Oakley_
  • Oakley_
  • 2016年09月12日 11:16
  • 233

BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster

Description The cows are building a roller coaster! They want your help to design as fun a roller...

1649: [Usaco2006 Dec]Cow Roller Coaster

1649: [Usaco2006 Dec]Cow Roller Coaster Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 636  Solved...

bzoj1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 (搜索+剪枝)

1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 692  Solved: 4...

poj 3257 Cow Roller Coaster(二维背包)

Cow Roller Coaster Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2575   Accepte...
  • WEYuLi
  • WEYuLi
  • 2013年07月03日 00:29
  • 920

[BZOJ1717][Usaco2006 Dec]Milk Patterns 产奶的模式(后缀数组)

错过的年华在北漠开出斑斓的紫薇花,却荒芜了轮回的春夏。

BZOJ 1650: [Usaco2006 Dec]River Hopscotch 跳石子

Description Every year the cows hold an event featuring a peculiar version of hopscotch that invo...

bzoj1717[Usaco2006 Dec]Milk Patterns 产奶的模式 (二分+hash)题解①

1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 993  Solved:...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:【BZOJ1649】[Usaco2006 Dec]Cow Roller Coaster【背包DP】
举报原因:
原因补充:

(最多只允许输入30个字)