Bzoj 1649: [Usaco2006 Dec]cow roller Coaster (DP) __bzoj

Source: Internet
Author: User

1649: [Usaco2006 Dec]cow roller coaster time limit: 5 sec   Memory MB br> submit: 710   solved: 358
[submit][status][discuss] Description

The cows are building a roller coaster! They want your help-as fun a roller coaster as possible, while keeping to the budget. The roller coaster is built on a long linear stretch to land of length L (1 <= l <= 1,000). The roller coaster comprises a collection of some of the N (1 <= n <= 10,000) different interchangable. Each component I has a fixed length WI (1 <= wi <= L). Due to varying terrain, the each component I can is only built starting at location XI (0 <= XI <= l-wi). The cows want to string together various roller coaster components starting in 0 and ending at L. Omponent (except) is the start of the next component. Each component I has a "fun rating" fi (1 <= fi <=-1,000,000) and a cost CI (1 <= ci <= 1000). The total fun of the roller Coster are the sum of the fun from each component used; The total cost is likewise the sum of the costs of each component used. The cows ' total budget iS B (1 <= b <= 1000). Help the cows determine the most fun roller coaster this they can build with their budget. The cows are going to build a roller coaster track. They want you to help find the most interesting, but budget-compliant solution. The track of the    roller is connected by a number of rails and is extended from the x=0 to the X=l (1≤l≤1000) branch. The existing N (1≤n≤10000) root rails, the beginning of each rail (0≤XI≤L-&NBSP;WI), the length of Wi (l≤wi≤l), the interesting index Fi (1≤fi≤1000000), and the cost Ci (l≤ci≤1000) are known. Please make sure that an optimal scheme is used to make the most interesting index of the selected rails, while the sum of the cost is no more than B (1≤b≤1000).Input

* Line 1:three space-separated integers:l, N and B.

* Lines 2..n+1:line i+1 contains four space-separated, integers, WI, Fi, and Ci. Line 1th Enter L,n,b, and then N rows, four integers per line xi,wi,fi,ci. Output

* Line 1: "A single" is the "Maximum fun value" a roller-coaster can have while staying the within D meeting All of the other constraints. If It isn't possible to build a roller-coaster within budget, output-1.

Sample Input 5 6 0 2 6 2 3 5 6 0 1 2 1 1 1 1 3 1 2 5 4 3 2 Sample Output 2


DP[I][J] represents the maximum value of the first I m all paved and the cost is J

The second dimension is similar to 01 backpack


 #include <stdio.h> #include <string.h> #include <algorithm> using namespace std;
	Define LL long typedef struct RES {int x, y;
	int cost, Val;
		BOOL operator < (const Res &b) Const {if (Y<B.Y) return 1;
	return 0;
}}res;
Res s[10005];
LL dp[1005][1005];
	int main (void) {LL ans;
	int L, n, V, I, J, p;
	scanf ("%d%d%d", &l, &n, &v);
		for (i=1;i<=n;i++) {scanf ("%d%d%d%d", &s[i].x, &s[i].y, &s[i].val, &s[i].cost);
	S[i].y = S[I].X+S[I].Y;
	Sort (s+1, s+n+1);
	Memset (DP,-1, sizeof (DP));
	Dp[0][0] = 0;
	p = 1; for (i=1;i<=l;i++) {while (s[p].y==i && p<=n) {for (j=v;j>=s[p].cost;j--) {if (dp[s[p].x][j
				-S[P].COST]==-1) continue;
			DP[I][J] = max (dp[i][j], dp[s[p].x][j-s[p].cost]+s[p].val);
		} p++;
	ans =-1;
		for (i=0;i<=v;i++) {if (dp[l][i]==-1) continue;
	ans = max (ans, dp[l][i]);
	printf ("%lld\n", ans);
return 0; }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.