Groups
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.
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).
3 2 0 0 2 2 2 3 2 0 0 2 2 2
2 2HintThe third player must be making a mistake, since only 3 plays exist.
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=500;
int dp[N],s[N][N];
int main()
{
int n,i,j,ans,a,b;
while(~scanf("%d",&n))
{
memset(s,0,sizeof(s));
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
if(s[a][n-1-b]<n-a-b) s[a][n-1-b]++;
}
ans=0;
for(i=0;i<n;i++)
{
dp[i]=0;
for(j=i;j>=0;j--)dp[i]=max(dp[i],dp[j-1]+s[j][i]);
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return 0;
}
3251



被折叠的 条评论
为什么被折叠?



