• <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>

            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
            色综合合久久天天给综看| 久久综合久久伊人| 亚洲伊人久久综合中文成人网| 久久se这里只有精品| 久久久久久精品免费免费自慰| 国产产无码乱码精品久久鸭| 久久精品成人免费看| 麻豆一区二区99久久久久| 香蕉久久av一区二区三区| 国产亚洲综合久久系列| 久久久亚洲精品蜜桃臀| 青青草国产成人久久91网| 久久久国产打桩机| 三级韩国一区久久二区综合| 久久无码中文字幕东京热| 久久无码人妻一区二区三区| 国产精品一区二区久久不卡| 精品99久久aaa一级毛片| 超级碰碰碰碰97久久久久| 国产麻豆精品久久一二三| 久久丝袜精品中文字幕| 久久99精品国产自在现线小黄鸭 | 91久久精品国产成人久久| 久久国产三级无码一区二区| 久久香蕉超碰97国产精品| 欧美久久久久久午夜精品| 麻豆一区二区99久久久久| 久久青青草原精品国产软件| 99久久99这里只有免费的精品| 色8激情欧美成人久久综合电| 丰满少妇人妻久久久久久| 久久婷婷午色综合夜啪| 国产69精品久久久久99| 久久香综合精品久久伊人| 久久精品人人做人人爽电影| 久久久久噜噜噜亚洲熟女综合| 精品久久777| 嫩草影院久久99| 国产精品青草久久久久婷婷| 欧美黑人激情性久久| 国内精品久久久久久久久电影网|