码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4293 Groups

时间:2015-09-17 16:56:04      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

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\n",dp[n]);
19     }
20     return 0;
21 }
View Code

 

HDU 4293 Groups

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4816511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!