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. PHP-007(转)

    今天安装ecshop的时候最上面出现了一个错误提示:Strict Standards: Only variables should be passed by reference in F:\www.x ...

  2. angularjs基础——变量绑定

    1)弄一个ng-app(angularjs 应用) 2)在里面用ng-model(angularjs 模型)就可以定义一个模型变量 3)使用模版方法就可以输出变量了(例如:{{name}}) 示例: ...

  3. 在(MRv1)中JobTracker工作方式

    在 Hadoop MapReduce 中,JobTracker 具有两种不同的职责: 管理集群中的计算资源,这涉及到维护活动节点列表.可用和占用的 map 和 reduce slots 列表,以及依据 ...

  4. Solr可视化简单的操作

    Solr可视化简单的操作 启动solr服务器;在浏览器输入Tomcat启动: http://192.168.191.142:8080/solr/#/ Ø  添加core,首先在存放home的文件下创建 ...

  5. poj_3977 折半枚举

    题目大意 给定N(N<=35)个数字,每个数字都<= 2^15. 其中一个或多个数字加和可以得到s,求出s的绝对值的最小值,并给出当s取绝对值最小值时,需要加和的数字的个数. 题目分析 需 ...

  6. java框架---->quartz整合spring(一)

    今天我们学习一下quartz的定时器的使用.年轻时我们放弃,以为那只是一段感情,后来才知道,那其实是一生. quartz的简单实例 测试的项目结构如下: 一.pom.xml中定义quartz的依赖 & ...

  7. LeetCode——Ugly Number

    Description: Write a program to check whether a given number is an ugly number. Ugly numbers are pos ...

  8. 如何使用腾讯云开发一款 AR 应用介绍

    版权声明:本文由张亚舒原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/117 来源:腾云阁 https://www.qclo ...

  9. Egret P2 ( 一) 掉落的小球

    实际效果(蛋疼这个gif制作软件,帧率太低....): 一 Egret和P2的坐标系 首先了解下P2和Egret的坐标系. 某人链接:http://blog.csdn.net/qilei2010/ar ...

  10. 树形DP求各点能走到的最远距离

    hdu2196 Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...