poj 1036 Gangsters
共 1116字,需浏览 3分钟
·
2021-11-18 08:28
Gangsters
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
歹徒
描述
N个歹徒要去餐厅。第 i 个歹徒在 Ti 时间出现并拥有繁荣 Pi。餐厅的门有 K+1 个打开状态,由 [0, K] 范围内的整数表示。开放状态可以在一个单位时间内发生变化;即它要么打开一个,要么关闭一个,要么保持不变。在初始时刻,门是关闭的(状态 0)。只有当门专门为他打开时,第 i 个歹徒才进入餐厅,即当开放状态与他的粗壮 Si 一致时。如果在歹徒来到餐厅的那一刻,开放的状态不等于他的粗壮,那么歹徒就走了,再也不回来了。
餐厅在 [0, T] 的时间间隔内工作。
目标是通过适当地打开和关闭门来聚集餐厅中最繁荣的歹徒。
输入
? 输入文件的第一行包含用空格分隔的值 N、K 和 T。(1 <= N <= 100 ,1 <= K <= 100 ,0 <= T <= 30000 )
?输入文件的第二行包含歹徒来到餐厅 T1, T2, .. ., TN,以空格分隔。( 0 <= Ti <= T for i = 1, 2, ..., N)
?输入文件的第三行包含暴徒P1, P2, ..., PN的繁荣值,用空格隔开. ( 0 <= Pi <= 300 for i = 1, 2, ..., N)
?输入文件的第四行包含歹徒 S1, S2, ..., SN 的粗壮度值,以空格分隔. ( 1 <= Si <= K for i = 1, 2, ..., N)
输入文件中的所有值都是整数。
输出
将单个整数打印到输出文件中?餐厅中歹徒的最大繁荣总和。如果没有歹徒可以进入餐厅,则输出应为 0。
样本输入
4 10 20
10 16 8 16
10 11 15 1
10 7 1 8
样本输出
26
代码:
#include
#include
#include
#include
using namespace std;
struct node
{
int t, p, s;
}g[103];
bool cmp(node a, node b)
{
return a.t < b.t;
}
int dp[103];
int main()
{
int i, j;
int n, k, t;
while(scanf("%d%d%d", &n, &k, &t)==3)
{
for(i = 1; i <= n; i++)
scanf("%d", &g[i].t);
for(i = 1; i <= n; i++)
scanf("%d", &g[i].p);
for(i = 1; i <= n; i++)
scanf("%d", &g[i].s);
sort(g+1, g+n+1, cmp);
memset(dp, 0, sizeof(dp));
for(i = 1; i <= n; i++)
{
dp[i] = (g[i].t>=g[i].s)? g[i].p : 0;
for(j = 1; j {
if(!dp[j]) continue;
if(abs(g[i].s-g[j].s)<=g[i].t-g[j].t)
dp[i] = max(dp[i], dp[j]+g[i].p);
}
}
int ans = -1;
for(i = 1; i <=n; i++)
ans = max(ans, dp[i]);
printf("%d\n", ans);
}
return 0;
}