POJ 1036 Gangsters

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11782   Accepted: 3290

Description

N gangsters are going to a restaurant. The i-th gangster comes at the time Ti and has the prosperity Pi. The door of the restaurant has K+1 states of openness expressed by the integers in the range [0, K]. The state of openness can change by one in one unit of time; i.e. it either opens by one, closes by one or remains the same. At the initial moment of time the door is closed (state 0). The i-th gangster enters the restaurant only if the door is opened specially for him, i.e. when the state of openness coincides with his stoutness Si. If at the moment of time when the gangster comes 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 file contains the values N, K, and T, separated
by spaces. (1 <= N <= 100 ,1 <= K <= 100 ,0 <= T <=
30000 )

?The second line of the input file contains the moments of time when
gangsters come to the restaurant T1, T2, ..., TN, separated by spaces. (
0 <= Ti <= T for i = 1, 2, ..., N)

?The third line of the input file contains the values of the
prosperity of gangsters P1, P2, ..., PN, separated by spaces. ( 0 <=
Pi <= 300 for i = 1, 2, ..., N)

?The forth line of the input file contains the values of the
stoutness of gangsters S1, S2, ..., SN, separated by spaces. ( 1 <=
Si <= K for i = 1, 2, ..., N)

All values in the input file are integers.

Output

Print
to the output file the single integer ?the maximal sum of prosperity of
gangsters in the restaurant. In case when no gangster can enter the
restaurant the output should be 0.

Sample Input

4 10 20
10 16 8 16
10 11 15 1
10 7 1 8

Sample Output

26

CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 100 + 10

using namespace std;

int n, k, t;
struct node{
    int T, P, S;
}a[MAX_N];
int F[MAX_N];

bool cmp(node a,node b){ return a.T < b.T; }
int main(){
    scanf("%d%d%d", &n, &k, &t);
    REP(i, 1, n) scanf("%d", &a[i].T);
    REP(i, 1, n) scanf("%d", &a[i].P);
    REP(i, 1, n) scanf("%d", &a[i].S);

    sort(a + 1, a + n + 1, cmp);
    REP(i, 1, n){
        if(a[i].T >= a[i].S) F[i] = a[i].P;
        else {F[i] = -1; continue; }
        REP(j, 1, i - 1)
            if(abs(a[i].S - a[j].S) <= abs(a[i].T - a[j].T)) F[i] = max(F[i], F[j] + a[i].P);
    }

    int ans = 0;
    REP(i, 1, n) ans = max(ans, F[i]);
    printf("%d\n", ans);
    return 0;
}
 
时间: 2024-10-13 12:31:11

POJ 1036 Gangsters的相关文章

poj 1036

题目: 戳原题 题意: N 个盗贼去一个饭店,第i个盗贼在Ti时间来,他拥有Pi的财富.这个饭店的门有K+1种开放的状态,用[0,K]表示.这些状态能够被一个盗贼改变在一个时间单位内,要么把它打开,要么把它关闭,或者就是维持原状.在初始时刻这些门都是关闭着的.第i个盗贼进入了饭店仅当这个门是专门为他所开放的时候,也就是说这个门的状态与他的坚强程度Si一致的时候.当盗贼来到饭店的这一刻,如果开放的状态不等于盗贼的坚强程度的时候,这个盗贼就不会再来了.饭店的工作时间为区间[0,T]目标是帮 盗贼在饭

{POJ}{动态规划}

动态规划与贪心相关: {POJ}{2479}{Maximum Sum} (DP) 摘要: 题意:给定n个数,求两段连续子列的最大和.思路:先从左向右dp,求出一段连续子列的最大和,再从右向左dp,求出两段连续子列的最大和,方法还是挺经典的. {POJ}{1036}{Gansters} (DP) 摘要: 题意:有个伸缩门,门的宽度0~K,每个时间可以伸长或缩短1个单位,有N个流氓,他们在T时刻到达,如果这时门的宽度正好与他们的stoutness相等时,便可获得一定的收入,问最大的收入是多少. 思路

[转] POJ DP问题

列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 1952, 1953, 1958, 1959, 1962, 1975, 1989, 2018, 2029, 2039, 2063, 20

DP题目列表/弟屁专题

声明: 1.这份列表不是我原创的,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号:容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1414, 1456, 1458, 1609, 1644, 1664, 1690, 1699, 1740, 1742, 1887, 1926, 1936, 195

poj 1703 Find them, Catch them

Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 46119   Accepted: 14193 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Drago

(带关系)Find them, Catch them -- poj -- 1703

链接: http://poj.org/problem?id=1703 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36768   Accepted: 11294 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the cit

POJ 1703 Find them, Catch them(数据结构-并查集)

Find them, Catch them Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal b

POJ 1703 Find them, Catch them (数据结构-并查集)

Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31102   Accepted: 9583 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon

poj 1703(带权并查集)

Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31840   Accepted: 9807 Description The police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon