青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設計空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6


 

Cow Roller Coaster
Time Limit:2000MS  Memory Limit:65536K
Total Submit:797 Accepted:236

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 ≤ WiL). Due to varying terrain, each component i can be only built starting at location Xi (0 ≤ XiL - 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.

 

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.

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

 

Hint
Taking the 3rd, 5th and 6th components gives a connected roller-coaster with fun value 17 and cost 7. Taking the first two components would give a more fun roller-coaster (25) but would be over budget.

Source
USACO 2006 December Silver

在DP題中 狀態的選擇往往是至關重要的 要滿足能完整描敘一個狀態的信息 不遺漏 不多余
而有時候卻發現一個狀態的目標元素有兩個。比如這個題目中典型的可以看出 費用和收益是一個狀態的2個目標元素。而一般而言碰到這種情況 我們都會把其中一個元素放到狀態中去 是一個狀態的目標值確定下來做DP 其實從本質上來說 是一個枚舉性質的DP 即枚舉一個目標元素的所有可能值 在某個具體的值下面做DP
所以 聰明的朋友一定想到了 我們要盡可能將范圍小的元素放入狀態中 對
所以此題的狀態設置為dp[i][j] 代表修建房子到i地址時使用費用為j的時候的最大收益值
這題的狀態轉移是分散的 因此最好是對于每個Component做一次轉移 呵呵
講了這么多理論 其實沒什么深奧的 背包模型想大家應該都非常熟悉了 其實背包模型不是上面所說的一種特例么?只是前面所說的方法可以應用與2個甚至多個目標元素的情況

 1#include <string.h>
 2#include <stdio.h>
 3#include <algorithm>
 4using namespace std;
 5
 6const int MAXINT = 200000000;
 7const int N = 1010;
 8const int M = 10010;
 9int L, n, cost;
10int dp[N][N]; //iµØÖ·, C×Ücost
11struct Node { int st, l, f, c; } p[M];
12
13bool operator<(const Node& a, const Node& b) { return a.st < b.st; }
14
15#define Max(a, b) ((a) > (b) ? (a) : (b))
16
17int main() {
18 scanf("%d %d %d"&L, &n, &cost);
19 int i, j;
20 for(i = 0; i < n; ++i) {
21  scanf("%d %d %d %d"&p[i].st, &p[i].l, &p[i].f, &p[i].c);
22 }
23
24 sort(p, p + n);
25
26 for(i = 0; i <= L; ++i)
27  for(j = 0; j <= cost; ++j)
28   dp[i][j] = -MAXINT;
29 dp[0][0= 0;
30
31 for(i = 0; i < n; i++) {
32  int& st = p[i].st, &= p[i].l, &= p[i].f, &= p[i].c;
33  for(j = 0; j < cost; ++j) if(dp[st][j] >= 0) {
34   dp[st + l][j + c] = Max( dp[st+l][j+c], dp[st][j] + f );
35  }
36 }
37
38 int max = -MAXINT;
39 for(i = 0; i <= cost; ++i) { //cost 
40  if(dp[L][i] > max)
41   max = dp[L][i];
42 }
43
44 if(max == -MAXINT) max = -1;
45
46 printf("%d\n", max);
47
48 return 0;
49}
50
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美精品一二三| 亚洲欧美成人网| 男女av一区三区二区色多| 新67194成人永久网站| 一本色道88久久加勒比精品| 亚洲缚视频在线观看| 亚洲一区二区三区高清| 国产在线乱码一区二区三区| 欧美日韩免费一区二区三区| 欧美日韩亚洲一区在线观看| 国产精品美女午夜av| 国产性色一区二区| 亚洲国产一区二区a毛片| 亚洲精选91| 欧美在线亚洲在线| 欧美高清在线播放| 一区二区三区精品久久久| 久久精品人人| 欧美日韩成人在线视频| 国产日韩欧美在线| 亚洲毛片一区| 久久黄色小说| 亚洲美女啪啪| 久久精品系列| 国产精品白丝av嫩草影院| 在线日本高清免费不卡| 亚洲一区二区影院| 欧美成人xxx| 亚洲欧美日韩一区二区在线 | 久久av在线| 亚洲激情在线播放| 久久精品一二三区| 国产精品视频区| 一区二区三区久久久| 免费av成人在线| 亚洲欧美视频在线| 欧美网站大全在线观看| 亚洲精品男同| 欧美成人精品1314www| 亚洲欧美日韩在线综合| 欧美午夜无遮挡| 99精品免费网| 亚洲国产精品高清久久久| 久久精品人人做人人综合| 国产精品专区h在线观看| 亚洲少妇最新在线视频| 亚洲黄色性网站| 免费视频最近日韩| 亚洲国产精品黑人久久久| 久久九九国产精品怡红院| 亚洲一区二区三区四区五区午夜| 欧美日本韩国| 一区二区欧美亚洲| 亚洲乱码国产乱码精品精98午夜| 免费视频久久| 亚洲美女中文字幕| 亚洲精品社区| 欧美精品久久天天躁| 亚洲精品视频中文字幕| 亚洲国产精品传媒在线观看| 久久这里有精品视频| 一区精品久久| 欧美激情中文字幕乱码免费| 小黄鸭精品密入口导航| 国产精品a久久久久| 99亚洲一区二区| 91久久精品一区| 麻豆精品精华液| 亚洲免费不卡| 一本一本a久久| 国产精品久久久亚洲一区| 亚洲欧美国产高清va在线播| 亚洲影院在线观看| 国产主播一区二区三区四区| 久久男人av资源网站| 久久综合九色综合久99| 91久久精品一区| 夜夜嗨av一区二区三区| 国产精品乱人伦一区二区| 久久精品国产99国产精品| 久久视频国产精品免费视频在线 | 久久精品亚洲精品| 亚洲日本无吗高清不卡| aa国产精品| 国产真实精品久久二三区| 欧美韩日亚洲| 国产精品人成在线观看免费 | 亚洲精选成人| 亚洲天堂免费观看| 黄色av一区| 99精品欧美一区二区三区综合在线| 国产精品美女久久久免费| 免费91麻豆精品国产自产在线观看| 欧美成在线视频| 欧美一区二区黄| 欧美承认网站| 欧美一区二区私人影院日本| 久久综合99re88久久爱| 午夜老司机精品| 另类天堂视频在线观看| 亚洲欧美日韩精品一区二区 | 国产精品入口夜色视频大尺度| 久久久久天天天天| 欧美午夜精品久久久久久人妖 | 噜噜噜91成人网| 亚洲欧美三级伦理| 免费人成网站在线观看欧美高清| 亚洲影视中文字幕| 久久网站热最新地址| 欧美一级视频精品观看| 另类国产ts人妖高潮视频| 欧美一区二区三区在线视频 | 99国产精品视频免费观看一公开| 亚洲欧美国产制服动漫| 亚洲精品三级| 久久精选视频| 欧美视频不卡中文| 老鸭窝亚洲一区二区三区| 亚洲永久免费av| 欧美激情精品久久久久久| 午夜精品久久99蜜桃的功能介绍| 美女爽到呻吟久久久久| 亚久久调教视频| 欧美母乳在线| 亚洲第一免费播放区| 国产主播一区二区| 亚洲天堂成人在线观看| 亚洲天堂视频在线观看| 欧美激情国产日韩| 欧美激情在线狂野欧美精品| 国内精品久久久| 亚洲一区日韩| 亚洲欧美在线免费观看| 国产精品国码视频| 国产精品99久久久久久久vr | 欧美偷拍一区二区| 亚洲精品视频免费| 日韩视频在线永久播放| 女仆av观看一区| 亚洲激情综合| 亚洲精品社区| 欧美精品一卡| 一区二区三区国产在线观看| 国产精品99久久久久久白浆小说| 欧美精品久久久久久| 日韩一区二区久久| 午夜久久电影网| 国产真实精品久久二三区| 欧美亚洲视频| 美女诱惑一区| 亚洲激情在线观看视频免费| 美女日韩欧美| 亚洲人精品午夜在线观看| 亚洲天堂免费观看| 国产日韩欧美高清| 久久久999精品免费| 欧美v日韩v国产v| 一本久久青青| 国产欧美日韩在线观看| 久久精品国产99| 欧美高清一区二区| 中日韩高清电影网| 国产麻豆91精品| 老司机午夜精品视频在线观看| 91久久午夜| 亚欧成人在线| 亚洲精品欧美一区二区三区| 欧美视频在线观看| 久久国产精品72免费观看| 欧美成人免费全部观看天天性色| 亚洲另类在线视频| 国产日本欧美在线观看| 欧美第十八页| 性刺激综合网| 亚洲国产欧美一区二区三区久久 | 久久精品av麻豆的观看方式| 欲香欲色天天天综合和网| 欧美日韩国产综合久久| 亚洲欧美日韩在线不卡| 免费人成精品欧美精品| 久久免费观看视频| 一区二区国产日产| 亚洲一区在线免费观看| 久久久久网站| 狠狠狠色丁香婷婷综合久久五月| 伊人久久亚洲美女图片| 在线中文字幕不卡| 亚洲国产高清一区| 久久精品一区二区三区不卡牛牛 | 你懂的视频一区二区| 亚洲一区二区动漫| 伊伊综合在线| 欧美午夜宅男影院| 女人天堂亚洲aⅴ在线观看| 99热免费精品| 欧美激情中文不卡| 久久综合久久久久88| 欧美一区二区三区四区夜夜大片| 亚洲精品在线一区二区| 黄色av日韩|