[UVA][dp] 672 - Gangsters@Morris' Blog|PChome Online 人新台
2014-01-24 09:40:30| 人1,398| 回0 | 上一篇 | 下一篇

[UVA][dp] 672 - Gangsters

0 收藏 0 0 站台


 Gangsters 

N gangsters are going to a restaurant. The i-th gangster comes at thetime Ti and has the prosperity Pi. The door of the restaurant hasK+1 states of openness expressed by the integers in the range [0, K]. Thestate of openness can change by one in one unit of time; i.e. it either opensby one, closes by one or remains the same. At the initial moment of time thedoor is closed (state 0). The i-th gangster enters the restaurant only if thedoor is opened specially for him, i.e. when the state of openness coincideswith his stoutness Si. If at the moment of time when the gangstercomes to the restaurant the state of openness is not equal to his stoutness,then the gangster goes away and never returns.


The restaurant works in the interval of time [0, T].


The goal is to gather the gangsters with the maximal total prosperity in the restaurant by opening and closing the door appropriately.

Input 

The first line of the input is an integer M, then a blank line followed by M datasets. There is a blank line between datasets.

The first line of each dataset contains the values N, K, and T,separated by spaces. ($1 le N le 100, 1 le K le 100, 0 le T le 30000$)

The second line of the dataset contains the moments of time whengangsters come to the restaurant $T_1, T_2, dots, T_N$,separated byspaces. ($0 le T_i le T$for $i = 1, 2, dots, N$)

The third line of the dataset contains the values of the prosperity ofgangsters $P_1, P_2 , dots, P_N$,separated by spaces. ($0 le P_i le 300$for $i = 1, 2, dots, N$)

The forth line of the dataset contains the values of the stoutness ofgangsters $S_1, S_2, dots, S_N$,separated by spaces. ($1 le S_i le K$for$i = 1, 2, dots, N$)


All values in the input file are integers.

Output 

For each dataset, print the single integer - the maximal sum of prosperity of gangsters in the restaurant. In case when nogangster can enter the restaurant the output should be 0.Print a blank line between datasets.

Sample Input 

14 10 2010 16 8 1610 11 15 110 7 1 8/font>

Sample Output 

26



Miguel Revilla
2000-05-22

目描述:


一家餐在有 N 位流氓,家店的很特殊,每刻可以大+1不+0小-1,

第 0 刻大小 0,而每流氓,如果大小好等於他所要求的,他便消。

反之否,求最大消。

目解法:

作 DP,dp[i][j] : 在 i 大小 j 的最大消。

// 一始想排序,把 i 替成第 i 人,由於可能重,理。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct Gangster {
    int t, p, s;
};
int dp[30005][105], w[30005][105];
int main() {
    int testcase;
    int N, K, T;
    int i, j, k;
    Gangster D[105];
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%d %d %d", &N, &K, &T);
        for(i = 1; i <= N; i++)    scanf("%d", &D[i].t);
        for(i = 1; i <= N; i++)    scanf("%d", &D[i].p);
        for(i = 1; i <= N; i++)    scanf("%d", &D[i].s);
        memset(w, 0, sizeof(w));
        memset(dp, 0, sizeof(dp));
        for(i = 1; i <= N; i++)
            w[D[i].t][D[i].s] += D[i].p;
        int ret = 0;
        for(i = 0; i < T; i++) {
            for(j = min(i, K); j >= 0; j--) {
                if(j)
                    dp[i+1][j-1] = max(dp[i+1][j-1], dp[i][j] + w[i+1][j-1]);
                dp[i+1][j] = max(dp[i+1][j], dp[i][j] + w[i+1][j]);
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + w[i+1][j+1]);
            }
        }
        for(i = 0; i <= K; i++)       
            ret = max(ret, dp[T][i]);
        printf("%d\n", ret);
        if(testcase)
            puts("");
    }
    return 0;
}

台: Morris
人(1,398) | 回(0)| 推 (0)| 收藏 (0)|
全站分: | 人分: UVA |
此分下一篇:[UVA][搜索] 653 - Gizilch
此分上一篇:[UVA] 10461 - Difference

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86