zoukankan      html  css  js  c++  java
  • [poj 1036]gangsters

    poj 1036

    Gangsters

    Description

    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 stoutness Si. 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 file contains the values N, K, and T, separated by spaces. (1 <= N <= 100 ,1 <= K <= 100 ,0 <= T <= 30000 )
    ?The second line of the input file contains the moments of time when gangsters come to the restaurant T1, T2, ..., TN, separated by spaces. ( 0 <= Ti <= T for i = 1, 2, ..., N)
    ?The third line of the input file contains the values of the prosperity of gangsters P1, P2, ..., PN, separated by spaces. ( 0 <= Pi <= 300 for i = 1, 2, ..., N)
    ?The forth line of the input file contains the values of the stoutness of gangsters S1, S2, ..., SN, separated by spaces. ( 1 <= Si <= K for i = 1, 2, ..., N)
    All values in the input file are integers.

    Output

    Print to the output file 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.

    Sample Input

    4 10 20

    10 16 8 16

    10 11 15 1

    10 7 1 8

    Sample Output

    26

    大致题意:

    有n个强盗,门上有一k值,每过一个时间,k不变或加1减1,当k与强盗的数值一样时,强盗才能入内,此时加上强盗的繁荣值

     

    思路:

    Dp[i]表示前i个强盗,最大的繁荣值

    循环判断i前的所有强盗能不能与当前这个接上

    取最大值

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cmath>
     4 #include<cstdio>
     5 #include<cstdlib>
     6 #include<cstring>
     7 
     8 using namespace std;
     9 
    10 struct data
    11 {
    12     int t,p,s;
    13     bool operator <(const data &a)const
    14     {
    15         if(t<a.t)return true;
    16         return false;
    17     }
    18 }a[101];
    19 int read()
    20 {
    21     int x=0,f=1;
    22     char ch=getchar();
    23     while(ch<'0' || ch<'9'){if(ch=='-')f=-1;ch=getchar();}
    24     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    25     return x*f;
    26 }
    27 int n,k,t,dp[101],ans;
    28 int main()
    29 {
    30     cin>>n>>k>>t;
    31     memset(dp,-1,sizeof(dp));
    32     dp[0]=0;
    33     for(int i=1;i<=n;i++)cin>>a[i].t;
    34     for(int i=1;i<=n;i++)cin>>a[i].p;
    35     for(int i=1;i<=n;i++)cin>>a[i].s;
    36 
    37     sort(a+1,a+n+1);
    38     for(int i=1;i<=n;i++)
    39     {
    40         for(int j=0;j<i;j++)
    41         {
    42             if(a[i].t-a[j].t>=abs(a[j].s-a[i].s) && dp[j]!=-1)
    43             {
    44                 dp[i]=max(dp[i],dp[j]+a[i].p);
    45             }
    46         }
    47         if(dp[i]>ans)ans=dp[i];
    48     }
    49     printf("%d",ans);
    50     system("pause");
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    JAVA List对象与json串互相转换
    git错误提示:fatal: remote origin already exists.
    eclipse中js中ctrl+鼠标点击方法出现 the resource is not on the include path of a javaScript project
    JS根据日期获取这周的周一
    jquery基本操作
    redux+react-redux+示例的快速上手体验
    用 async/await 来处理异步
    Git使用详细教程
    SVN里直接把本地目录纳入管理
    修改npm安装的全局路径和配置环境变量的坑
  • 原文地址:https://www.cnblogs.com/taojy/p/7144635.html
Copyright © 2011-2022 走看看