zoukankan      html  css  js  c++  java
  • (HDU 4293) Groups (区间DP)

    Groups

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1959    Accepted Submission(s): 774


    Problem Description
      After the regional contest, all the ACMers are walking alone a very long avenue to the dining hall in groups. Groups can vary in size for kinds of reasons, which means, several players could walk together, forming a group.
      As the leader of the volunteers, you want to know where each player is. So you call every player on the road, and get the reply like “Well, there are Ai players in front of our group, as well as Bi players are following us.” from the ith player.
      You may assume that only N players walk in their way, and you get N information, one from each player.
      When you collected all the information, you found that you’re provided with wrong information. You would like to figure out, in the best situation, the number of people who provide correct information. By saying “the best situation” we mean as many people as possible are providing correct information.
     
    Input
      There’re several test cases.
      In each test case, the first line contains a single integer N (1 <= N <= 500) denoting the number of players along the avenue. The following N lines specify the players. Each of them contains two integers Ai and Bi (0 <= Ai,Bi < N) separated by single spaces.
      Please process until EOF (End Of File).
     
    Output
      For each test case your program should output a single integer M, the maximum number of players providing correct information.
     
    Sample Input
    3 2 0 0 2 2 2 3 2 0 0 2 2 2
     
    Sample Output
    2 2
     
    F**K这道奇葩的题真是坑了我好半天。
    思路真的是好奇特。
    因为一个团体中的人数是不确定的,用一个二维数组表示【i,j】作为一个团体时,当中有多少人了说真话。
    输入时可以直接特判某些情况的错误,最后用一个一维dp解出从0到i最多几人说了真话,dp【n】就是答案
     
    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<set>
    #include<map>
    #include<string.h>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #define LL long long
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    
    using namespace std;
    
    int dp[510][510];
    
    int main()
    {
        int n;
       while(~scanf("%d",&n))
       {
           memset(dp,0,sizeof(dp));
           for(int i=1;i<=n;i++)
           {
               int a,b;
               scanf("%d%d",&a,&b);
               if(dp[a+1][n-b]<n-b-a&&a+b+1<=n)
                dp[a+1][n-b]++;
           }
           int a[510]={0};
           for(int j=1;j<=n;j++)
            for(int i=0;i<j;i++)
                {
                    a[j]=max(a[j],a[i]+dp[i+1][j]);
                }
            printf("%d
    ",a[n]);
       }
       return 0;
    }
     
    此地非逐弃者之王座,彼方乃行愿者之归所。无限清澈,星界银波。
  • 相关阅读:
    NHibernate初学者指南系列文章导航
    c# 类一般在哪里实例化,是在类内、方法内还是其他地方?
    日期和时间的正则表达式
    virtual和abstract区别
    VS2010和选中代码相同的代码的颜色设置,修改高亮颜色
    SqlServer表和EXCEL数据互相复制方法
    C#操作XML的方法
    1、Spring Boot 2.x 简介
    C语言学习系列(六)基本语法
    C语言学习系列(六)存储类
  • 原文地址:https://www.cnblogs.com/brotherHaiNo1/p/8525955.html
Copyright © 2011-2022 走看看