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. raw_input()

    raw_input() 用于接收标准输入,并把标准输入当成字符串类型来处理,只能在 Python2 中使用,Python3 中没有这个函数 #!/usr/bin/env python #-*- cod ...

  2. Tomcat服务器的搭建

    一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...

  3. Bootloader之uBoot简介(转)

    来自http://blog.ednchina.com/hhuwxf/1915416/message.aspx,感谢作者 一.Bootloader的引入从前面的硬件实验可以知道,系统上电之后,需要一段程 ...

  4. android基础组件---->Spinner的使用

    Spinner提供了一个快速的方式从集合中选择值.在默认状态下,一个Spinner显示的是当前选择的值.触摸Spinner会显示一个下拉菜单,用户可以从中选择一个值.今天我们就开始Spinner的学习 ...

  5. this、target、currentTarget

    this:绑定事件所触发行为的对象 target:最开始冒泡的的对象 currentTarget:事件触发行为的对象 this == target currentTarget和this 是target ...

  6. linux的ls命令输出结果的逐条解释

    转自:http://blog.csdn.net/god123209/article/details/7193485 ls 命令的含义是list显示当前目录中的文件名字.注意不加参数它显示除隐藏文件外的 ...

  7. 一键搞定JavaEE应用,JRE+Tomcat+Mysql-JaveEE绿色运行环境JTM0.9版 (转载)

    这是一个集成了jre,tomcat,mysql的绿色运行环境, 直接解压之后就可以运行.不需要用户自己安装jre,tomcat,mysql,一键到位,看起来像是桌面式的web应用.换句话说,就像是we ...

  8. sqlserver 2012隐藏查询结果窗口

    1, 08r2的时候都是可以用 ctrl+r隐藏的 到了2012就不行了 方法 . 2, 快捷键的设置

  9. POI3的资料整理

    转自http://aman.cao.blog.163.com/blog/static/32951336201010823557408/ POI3的资料整理一.POI简介 Jakarta POI 是ap ...

  10. RSA library