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. GIS-012-ArcGIS JS API 绘图

    Name Description ARROW Draws an arrow. CIRCLE Draws a circle. DOWN_ARROW Draws an arrow that points ...

  2. linux安装oracle11g步骤

    1. 修改用户限制 root用户:修改 /etc/security/limits.conf 文件,加上下面的参数 oracle soft nproc 2047 oracle hard nproc 16 ...

  3. ajax如何上传文件

    PHP: <?php /** * Created by PhpStorm. * User: DELL * Date: 2017/11/23 * Time: 10:57 */ header(&qu ...

  4. 【go】用Golang的 http 包建立 Web 服务器

    web.go package main import ( "fmt" "log" "net/http" "strings" ...

  5. 广义表操作 (ava实现)——广义表深度、广义表长度、打印广义表信息

    广义表是对线性表的扩展——线性表存储的所有的数据都是原子的(一个数或者不可分割的结构),且所有的数据类型相同.而广义表是允许线性表容纳自身结构的数据结构. 广义表定义: 广义表是由n个元素组成的序列: ...

  6. fedora/centos7防火墙FirewallD详解

    1 使用 FirewallD 构建动态防火墙 1.1 “守护进程” 1.2 静态防火墙(system-config-firewall/lokkit) 1.3 使用 iptables 和 ip6tabl ...

  7. LeetCode——Happy Number

    Description: Write an algorithm to determine if a number is "happy". A happy number is a n ...

  8. bigpipe&bigrender

    bigpipe: 先输出页面的整体布局,在按块输出输出页面的每个部分.这样可以让服务器的运算.网络的传输和浏览器的渲染并行.适用于服务器运算较慢的时候. bigrender: 主要在浏览器端,先将字符 ...

  9. Egret类class和module写法区别

    普通类 Test.ts class Test { public name:string = "Test"; public run(){ console.log(this.name) ...

  10. 问答项目---用户注册的那些事儿(PHP验证)

    JS 验证之后,还需要通过PHP验证: 提交过来的名称不一样,可以用字段映射: 在自动验证的时候,如果这个字段被映射,那么自动验证的时候,自动验证的就是 映射过后的字段: 控制器示例: //注册表单处 ...