zoukankan      html  css  js  c++  java
  • HDU 4293 Groups

    Groups

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 4293
    64-bit integer IO format: %I64d      Java class name: Main
     
      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
    Hint
    The third player must be making a mistake, since only 3 plays exist.

    Source

     
    $解题:动态规划,dp[i]表示前i个人正确的人数最多的值$
    $cnt[i][j]表示说前有i个人 后有j人的个数$
    $那么dp[i] = max(dp[i],dp[j] + cnt[j][n-i])$
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 510;
     4 int dp[maxn],cnt[maxn][maxn],n;
     5 int main(){
     6     int u,v;
     7     while(~scanf("%d",&n)){
     8         memset(dp,0,sizeof dp);
     9         memset(cnt,0,sizeof cnt);
    10         for(int i = 0; i < n; ++i){
    11             scanf("%d%d",&u,&v);
    12             if(u + v < n && cnt[u][v] < (n - u - v)) cnt[u][v]++;
    13         }
    14         for(int i = 1; i <= n; ++i){
    15             for(int j = 0; j < i; ++j)
    16                 dp[i] = max(dp[i],dp[j] + cnt[j][n-i]);
    17         }
    18         printf("%d
    ",dp[n]);
    19     }
    20     return 0;
    21 }
    View Code
  • 相关阅读:
    随笔12 java反射机制
    随笔11 J2EE中常用的名词解释
    随笔⑩ java中的基本数据类型的基础知识
    随笔⑨ java中的变量 --- 类变量(静态变量),final变量,成员变量,局部变量 java中的方法 --- 类方法(静态方法),final方法,成员方法(实例方法),构造方法
    随笔⑧ java中的存根类 --- Stub
    随笔⑦ Java中的比较 ==,equals以及精度对比较的影响
    随笔⑥ 关于线程 --- 线程操作的主要方法
    Jupyter notebook and Octave kernel installation
    [C7] Andrew Ng
    [C6] Andrew Ng
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4816511.html
Copyright © 2011-2022 走看看