zoukankan      html  css  js  c++  java
  • 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 NK, and T, separated by spaces. ($1 le N le 100, 1 le K le 100, 0 le T le 30000$)

    The second line of the dataset contains the moments of time when gangsters come to the restaurant$T_1, T_2, dots, T_N$, separated by spaces. ( $0 le T_i le T$ for $i = 1, 2, dots, N$)

    The third line of the dataset contains the values of the prosperity of gangsters $P_1, P_2 , dots, P_N$, separated by spaces. ( $0 le P_i le 300$ for $i = 1, 2, dots, N$)

    The forth line of the dataset contains the values of the stoutness of gangsters $S_1, S_2, dots, S_N$, separated by spaces. ( $1 le S_i le K$ for $i = 1, 2, dots, N$)


    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[105];
    int dp[30005][105];
    vector<int> F[30005];
    int main()
    {
        int cas;
        scanf("%d",&cas);
        int N,K,T;
        for(int cc=1; cc<=cas; ++cc){
            scanf("%d%d%d",&N,&K,&T);
            for(int i=0; i<=T; ++i){
                F[i].clear();
            }
            for(int i=0; i<N; ++i){
                 scanf("%d",&P[i].ti);
                 F[ P[i].ti  ].push_back(i);
            }
            for(int i=0; i<N; ++i)
                scanf("%d",&P[i].Pi);
            for(int i=0; i<N; ++i)
                scanf("%d",&P[i].Si);
            memset(dp,-1,sizeof(dp));
            int ans=0;
            dp[0][0]=0;
            for(int i=1; i<=T; ++i){
                 int sz = F[i].size();
                 for(int j=0; j<sz; ++j){
                     int loc =F[i][j];
                     int Si = P[loc].Si;
                     if(dp[i][Si]!=-1){
                         dp[i][Si]+=P[loc].Pi; continue;
                     }
                     if(Si-1>=0&&dp[i-1][Si-1]!=-1){
                         dp[i][Si]=max(dp[i][Si],dp[i-1][Si-1]+P[loc].Pi);
                     }
                     if(dp[i-1][Si]!=-1){
                        dp[i][Si]=max(dp[i][Si],dp[i-1][Si]+P[loc].Pi);
                     }
                     if(Si+1<=K&&dp[i-1][Si+1]!=-1){
                         dp[i][Si]=max(dp[i][Si],dp[i-1][Si+1]+P[loc].Pi);
                     }
                     ans=max(dp[i][j],ans);
                 }
                 for(int j=0; j<=K; ++j){
                     if(j-1>=0&&dp[i-1][j-1]!=-1) dp[i][j]=max(dp[i][j],dp[i-1][j-1]);
                     if(dp[i-1][j]!=-1)dp[i][j]=max(dp[i][j],dp[i-1][j]);
                     if(j+1<=K&&dp[i-1][j+1]!=-1) dp[i][j]=max(dp[i][j],dp[i-1][j+1]);
                     ans=max(dp[i][j],ans);
                 }
    
            }
    
    
            printf("%d
    ",ans);
            if(cc!=cas) printf("
    ");
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    Python 向列表中添加元素
    [python] 查找列表中重复的元素
    Excel文件的读写
    Oracle EBS AP 取消付款
    Oracle EBS AP取消核销
    Oracle EBS AP 创建贷项通知单并核销到相应发票
    Oracle EBS AR 其他API
    Oracle EBS AR 冲销收款
    Oracle EBS 银行账户API
    Oracle EBS AR 客户API
  • 原文地址:https://www.cnblogs.com/Opaser/p/4083051.html
Copyright © 2011-2022 走看看