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 A i players in front of our group, as well as B i players are following us.” from the i th 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 A i and B i (0 <= A i,B i < 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. 
         

题意:一堆人分成好多组,问每个人会告诉你他这组前面有多少人,后面有多少人。他们说的话不全对,问最多有多少人人说真话

又是一个神题==先排除撒谎都不会的那些说自己前面的人数+后面的人数大于总人数的,记录每次读入的区间出现次数,如果次数大于区间的长度,必然又有人说谎了,那么区间个数只能记上限咯。然后Dp转移看代码吧~~

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int Left[509],Right[509],g[509][509],dp[509];
int n;
int main()
{
  //  freopen("cin.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)scanf("%d%d",&Left[i],&Right[i]);
        memset(g,0,sizeof(g));
        for(int i=1;i<=n;i++)
        {
            if(Left[i]+Right[i]>=n)continue;
            int l=Left[i]+1,r=n-Right[i];
            g[l][r]++;
          //  printf("g=%d ",g[l][r]);
            if(g[l][r]>r-l+1)
                g[l][r]=r-l+1;
        //    printf("g=%d ",g[l][r]);
        }
     //   for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)printf("i=%d,j=%d,g=%d\n",i,j,g[i][j]);
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
        {
            for(int j=i;j<=n;j++)
            {
                if(g[i][j]==0) dp[j]=max(dp[j-1],dp[j]);
                else dp[j]=max(dp[i-1]+g[i][j],dp[j]);
            }
        }
        printf("%d\n",dp[n]);
    }
    return 0;
}