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
  • 相关阅读:
    Sublime Text配置Python开发利器
    Python字符进度条
    安装和使用的django的debug_toolbar
    Python数组合并
    django创建项目
    Python的闭包
    Python获取对象的元数据
    Python的枚举类型
    Django的Model上都有些什么
    Git使用相关
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4816511.html
Copyright © 2011-2022 走看看