Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 2575 | Accepted: 1000 |
Description
The cows are building a roller coaster! They want your help to design as fun a roller coaster as possible, while keeping to the budget.
The roller coaster will be built on a long linear stretch of land of length L (1 ≤ L ≤ 1,000). The roller coaster comprises a collection of some of theN (1 ≤N ≤ 10,000) different interchangable components. Each componenti has a fixed lengthWi (1 ≤ Wi ≤L). Due to varying terrain, each componenti can be only built starting at locationXi (0 ≤ Xi ≤ L - Wi). The cows want to string together various roller coaster components starting at 0 and ending atL so that the end of each component (except the last) is the start of the next component.
Each component i has a "fun rating" Fi (1 ≤ Fi ≤ 1,000,000) and a costCi (1 ≤Ci ≤ 1000). The total fun of the roller coster is 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 isB (1 ≤B ≤ 1000). Help the cows determine the most fun roller coaster that they can build with their budget.
Input
Lines 2..N+1: Line i+1 contains four space-separated integers, respectively:Xi,Wi, Fi, and Ci.
Output
Sample Input
5 6 10 0 2 20 6 2 3 5 6 0 1 2 1 1 1 1 3 1 2 5 4 3 2 10 2
Sample Output
17
Hint
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <iostream>
using namespace std;
struct node
{
int x,w,f,c;
}com[10005];
int L,N,B;
int dp[1005][1005];
bool cmp(node a,node b)
{
return a.x+a.w<b.x+b.w;
}
int main()
{
while(cin>>L>>N>>B)
{
for(int i=0;i<N;i++)
cin>>com[i].x>>com[i].w>>com[i].f>>com[i].c;
sort(com,com+N,cmp);
memset(dp,-1,sizeof(dp));
for(int i=0;i<=B;i++) dp[0][i]=0;
for(int i=0;i<N;i++)
for(int j=0;j<=B-com[i].c;j++)
{
if(dp[com[i].x][j]<0) continue; //小于0时没法到达
dp[com[i].x+com[i].w][j+com[i].c]=max(dp[com[i].x+com[i].w][j+com[i].c],dp[com[i].x][j]+com[i].f);
}
cout<<dp[L][B]<<endl;
}
return 0;
}