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 NK, 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的更多相关文章

  1. [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总

    本文出自   http://blog.csdn.net/shuangde800 刘汝佳<算法竞赛入门经典-训练指南>的动态规划部分的习题Beginner  打开 这个专题一共有25题,刷完 ...

随机推荐

  1. IOS中数组的使用(NSArray, NSSet, NSDictionary)

    一.Foundation framework中用于收集cocoa对象(NSObject对象)的三种集合分别是: NSArray 用于对象有序集合(数组)NSSet 用于对象无序集合(集合) NSDic ...

  2. final,finally,finalize的区别

    1.final用于声明属性.方法和类,分别表示属性不可变.方法不可覆盖,类不可继承: 2.finally是异常处理语句结构的一部分,表示总是执行代码块: 3.finalize是Object类的一个方法 ...

  3. 《转》python学习(3)

    转自http://www.cnblogs.com/BeginMan/archive/2013/06/03/3114974.html 1.print语句调用str()函数显示,交互式解释器调用repr( ...

  4. webpack中,css中打包背景图,路径报错

    css-loader: //打包样式中背景图 { test: /\.(png|jpg)$/, loader: "url-loader?limit=8192&name=images/[ ...

  5. Sublime Less 自动编译成css

    1.note编译 .下载notejs https://nodejs.org/en/ .首先你要安装lessc.我是用npm包管理器直接安装的,只需要一条命令,如下: npm install less ...

  6. 解决:Bitmap too large to be uploaded into a texture exception

    前几天拿锤子手机做测试,启动页面的闪屏直接黑屏.. 所以看下日志,百度一下 找到解决方案,特此记录. 简单说就是硬件加速的时候,对图片的大小有限制.不同设备可能有不同的最大值.这个问题悲催的地方是,程 ...

  7. Linux操作系统上ADSL拨号上网的方法详解

    1.安装 yum install rp-pppoe.x86_64 2.配置PPPOE客户端软件 安装完软件包后,必须配置pppoe的配置文件/etc/ppp/pppoe.conf,从而让ADSL拨号时 ...

  8. 310实验室OTL问题

    1.首先是下载OTL文件包,网址是:github.com/O-T-L,可以直接点击网页上的下载链接,也可以使用unlix命令,git clone https://github.com/O-T-L/OT ...

  9. JS--页面返回/跳转/刷新(转载)

    原文: Javascript 返回上一页1. Javascript 返回上一页 history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3 ...

  10. wampserver3 集成环境 启动Apache失败

    前提:安装完成后,原先是能够启动服务,但是按照网上教程修改conf文件后就不能启动Apache, 方法: 1.查看Apache错误日志(无奈的是看不懂) 2.在cmd命令行中查看,(打开cmd,输入: ...