uva672
| Gangsters |
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 stoutnessSi. 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 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. (
)
The second line of the dataset contains the moments of time when gangsters come to the restaurant
, separated by spaces. (
for
)
The third line of the dataset contains the values of the prosperity of gangsters
, separated by spaces. (
for
)
The forth line of the dataset contains the values of the stoutness of gangsters
, separated by spaces. (
for
)
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 no gangster can enter the restaurant the output should be 0. Print a blank line between datasets.
Sample Input
1 4 10 20
10 16 8 16
10 11 15 1
10 7 1 8
Sample Output
26
这题说的是 给了了一扇门 ,每个时间段可以 增大1单位 减小1单位, 不增不减,(最大为k) 然后有n个人,每个人在某一时刻到达该点,当门的宽度等于该人是 该人可以进去
每个人都有一定的财富值 求进这扇门的最大财富值是多大 ,同 一 时 刻 可 以 有多人进去
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
struct point{
int ti,Si,Pi;
}P[];
int dp[][];
vector<int> F[];
int main()
{
int cas;
scanf("%d",&cas);
int N,K,T;
for(int cc=; cc<=cas; ++cc){
scanf("%d%d%d",&N,&K,&T);
for(int i=; i<=T; ++i){
F[i].clear();
}
for(int i=; i<N; ++i){
scanf("%d",&P[i].ti);
F[ P[i].ti ].push_back(i);
}
for(int i=; i<N; ++i)
scanf("%d",&P[i].Pi);
for(int i=; i<N; ++i)
scanf("%d",&P[i].Si);
memset(dp,-,sizeof(dp));
int ans=;
dp[][]=;
for(int i=; i<=T; ++i){
int sz = F[i].size();
for(int j=; j<sz; ++j){
int loc =F[i][j];
int Si = P[loc].Si;
if(dp[i][Si]!=-){
dp[i][Si]+=P[loc].Pi; continue;
}
if(Si->=&&dp[i-][Si-]!=-){
dp[i][Si]=max(dp[i][Si],dp[i-][Si-]+P[loc].Pi);
}
if(dp[i-][Si]!=-){
dp[i][Si]=max(dp[i][Si],dp[i-][Si]+P[loc].Pi);
}
if(Si+<=K&&dp[i-][Si+]!=-){
dp[i][Si]=max(dp[i][Si],dp[i-][Si+]+P[loc].Pi);
}
ans=max(dp[i][j],ans);
}
for(int j=; j<=K; ++j){
if(j->=&&dp[i-][j-]!=-) dp[i][j]=max(dp[i][j],dp[i-][j-]);
if(dp[i-][j]!=-)dp[i][j]=max(dp[i][j],dp[i-][j]);
if(j+<=K&&dp[i-][j+]!=-) dp[i][j]=max(dp[i][j],dp[i-][j+]);
ans=max(dp[i][j],ans);
} } printf("%d\n",ans);
if(cc!=cas) printf("\n");
} return ;
}
uva672的更多相关文章
- [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总
本文出自 http://blog.csdn.net/shuangde800 刘汝佳<算法竞赛入门经典-训练指南>的动态规划部分的习题Beginner 打开 这个专题一共有25题,刷完 ...
随机推荐
- mybatis 返回值类型是Map
<select id="selectByMemberKey" resultType="java.util.HashMap"> SELECT memb ...
- linux上如何快速删除一个目录
在linux中删除一个目录很简单,很多人还是习惯用rmdir,不过一旦目录非空,就陷入深深的苦恼之中,现在使用rm -rf命令即可解决.直接rm就可以了,不过要加两个参数-rf 即:rm -rf ...
- 说说SPI协议
SPI,是英语Serial Peripheral Interface 的缩写,顾名思义就是串行外围设备接口.SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用四根线,节约了芯片的管 ...
- HFS的远程命令执行漏洞(RCE)
一.HFS漏洞 1.影响版本 : 2.3c以前的2.3x版本 2.HFS: HFS是HTTP File Server,国外的一款HTTP 文件服务器软件,简单易上手. 3.漏洞描述: HTTP Fil ...
- 【BZOJ3437】小P的牧场 斜率优化
[BZOJ3437]小P的牧场 Description 背景 小P是个特么喜欢玩MC的孩纸... 描述 小P在MC里有n个牧场,自西向东呈一字形排列(自西向东用1…n编号),于是他就烦恼了:为了控制这 ...
- {sharepoint}It may have been deleted or renamed by another user
Symptom Consider the following scenario: We In the xslt: <xsl:param name="CustomItem"&g ...
- mysql导入数据失败:mysql max_allowed_packet 设置过小
mysql根据配置文件会限制server接受的数据包大小. 有时候大的插入和更新会受max_allowed_packet 参数限制,导致写入或者更新失败. 查看目前配置 show VARIABLES ...
- 微信小程序 --- page.json文件
page.json 文件用于配置当前目录.page.json文件里的配置可以修改 app.json 配置里面的 window:不能覆盖app.json文件里面的 tabBar / 网络超时/ debu ...
- pta 习题集 数列求和-加强版
给定某数字AA(1≤A≤91≤A≤9)以及非负整数NN(0≤N≤1000000≤N≤100000),求数列之和S=A+AA+AAA+⋯+AA⋯AS=A+AA+AAA+⋯+AA⋯A(NN个AA).例如A ...
- 【转】B2C电子商务系统设计精选
B2C电子商务系统研发——促销引擎设计(一)(Promotion Engine) B2C电子商务系统研发——商品SKU分析和设计(一) B2C电子商务系统研发——商品SKU分析和设计(二) 电商后台系 ...