有点类似背包 , 就是那样子搞...

------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep( i , n ) for( int i = 0 ;  i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
#define Rep( i , n ) for( int i = 1 ; i <= n ; ++i )
 
using namespace std;
 
const int maxn = int( 1e4 ) + 5;
const int maxl = 1000 + 5;
const int maxc = 1000 + 5;
const int inf = 0x7fffffff;
 
struct data {
int x , l , w , c;
void Read() {
scanf( "%d%d%d%d" , &x , &l , &w , &c );
}
bool operator < ( const data &rhs ) const {
return x < rhs.x || ( x == rhs.x && l < rhs.l );
}
};
 
data A[ maxn ];
int d[ maxl ][ maxc ];
 
int main() {
// freopen( "test.in" , "r" , stdin );
int L , n , MAX;
scanf( "%d%d%d" , &L , &n , &MAX );
MAX++;
rep( i , n ) 
   A[ i ].Read();
   
Rep( i , L )
   rep( j , MAX )
       d[ i ][ j ] = -inf;
rep( i , MAX )
   d[ 0 ][ i ] = 0;
sort( A , A + n );
rep( i , n ) {
data &o = A[ i ];
for( int j = o.c ; j < MAX ; j++ ) {
int &f = d[ o.x + o.l ][ j ];
f = max( f , d[ o.x ][ j - o.c ] + o.w );
}
}
int ans = 0;
rep( i , MAX ) ans = max( ans , d[ L ][ i ] );
ans > 0 ? printf( "%d\n" , ans ) : printf( "-1\n" );
return 0;
}

------------------------------------------------------------------------------------

1649: [Usaco2006 Dec]Cow Roller Coaster

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 440  Solved: 233
[Submit][Status][Discuss]

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 the N (1 <= N <= 10,000) different interchangable components. Each component i has a fixed length Wi (1 <= Wi <= L). Due to varying terrain, each component i can be only built starting at location Xi (0 <= Xi <= L-Wi). The cows want to string together various roller coaster components starting at 0 and ending at L 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 cost Ci (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 is B (1 <= B <= 1000). Help the cows determine the most fun roller coaster that they can build with their budget.

奶牛们正打算造一条过山车轨道.她们希望你帮忙,找出最有趣,但又符合预算的方案.  过山车的轨道由若干钢轨首尾相连,由x=0处一直延伸到X=L(1≤L≤1000)处.现有N(1≤N≤10000)根钢轨,每根钢轨的起点Xi(0≤Xi≤L- Wi),长度wi(l≤Wi≤L),有趣指数Fi(1≤Fi≤1000000),成本Ci(l≤Ci≤1000)均己知.请确定一种最优方案,使得选用的钢轨的有趣指数之和最大,同时成本之和不超过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, respectively: Xi, Wi, Fi, and Ci.

    第1行输入L,N,B,接下来N行,每行四个整数Xi,wi,Fi,Ci.

Output

* Line 1: A single integer that is the maximum fun value that a roller-coaster can have while staying within the budget and meeting all the other constraints. If it is not possible to build a roller-coaster within budget, output -1.

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
选用第3条,第5条和第6条钢轨

HINT

Source

BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )的更多相关文章

  1. BZOJ——1649: [Usaco2006 Dec]Cow Roller Coaster

    http://www.lydsy.com/JudgeOnline/problem.php?id=1649 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 7 ...

  2. bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster【dp】

    DAG上的dp 因为本身升序就是拓扑序,所以建出图来直接从1到ndp即可,设f[i][j]为到i花费了j #include<iostream> #include<cstdio> ...

  3. 【BZOJ】1649: [Usaco2006 Dec]Cow Roller Coaster(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1649 又是题解... 设f[i][j]表示费用i长度j得到的最大乐趣 f[i][end[a]]=ma ...

  4. bzoj1649 [Usaco2006 Dec]Cow Roller Coaster

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

  5. 【动态规划】bzoj1649 [Usaco2006 Dec]Cow Roller Coaster

    很像背包. 这种在一个数轴上进行操作的题常常需要对区间排序. f[i][j]表示距离到i时,花费为j时的权值之和. f[x[i]+l[i]][j+c[i]]=max{f[x[i]][j]+w[i]}( ...

  6. Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[ ...

  7. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

    直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...

  8. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐

    Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is graz ...

  9. bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐【dfs】

    从每个奶牛所在草场dfs,把沿途dfs到的草场的con都+1,最后符合条件的草场就是con==k的,扫一遍统计一下即可 #include<iostream> #include<cst ...

随机推荐

  1. 用OO方式写键盘字母小游戏

    <html>  <head>   <title>0.0</title>   <script>    window.onload=functi ...

  2. 柯南君:看大数据时代下的IT架构(9)消息队列之RabbitMQ--案例(RPC起航)

    二.Remote procedure call (RPC)(using the Java client) 三.Client interface(客户端接口) 为了展示一个RPC服务是如何使用的,我们将 ...

  3. C#动态编译、执行代码

    在开始之前,先熟悉几个类及部分属性.方法:CSharpCodeProvider.ICodeCompiler.CompilerParameters.CompilerResults.Assembly. 一 ...

  4. display的table和cell外加table-layout:fixed等分布局,外加换行,word-wrap:break-word

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. python中判断readline读到文件末尾

    fp = open('somefile.txt') while True: line = fp.readline() if not line: #等价于if line == "": ...

  6. asp.net弹出多个模态窗口

    asp.net中无限制弹出模态窗口 特点: 1.       可以在模态窗口上再弹出模态窗口,不限制次数 2.       弹出窗口的支持拖放,及调整大小 3.       弹出窗口关闭后可以动态控制 ...

  7. 内容高度小于窗口高度时版权div固定在底部

    <!doctype html><html><head><meta charset="utf-8"><title>文档内容 ...

  8. 权威指南学习心得-浏览器中的js

    window对象:表示web了浏览器的一个窗口或窗体(winow属性引用自身) 含有以下属性:location包含Location对象,指定当前显示在窗口中URL,允许脚本往窗口里载入新的URL 含有 ...

  9. SQL学习之汇总数据之聚集函数

    一. 1.我们经常需要汇总数据而不用把他们实际检索出来,为此SQL提供了专门的函数,以便于分析数据和报表生成,这些函数的功能有: (1)确定表中行数(或者满足单个条件或多个条件或包含某个特定值的行数) ...

  10. iOS中点击背景收键盘

    这一次给大家带来的是ios中点击背景如何收键盘(感觉不错给个赞