hdu 4293 poj 2168 dp

本文深入探讨了在复杂信息流中如何高效处理和分析数据的关键技术与策略,包括数据挖掘、数据工程、算法优化等核心领域,旨在帮助开发者提升数据处理能力,实现更智能的数据分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Groups

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 153    Accepted Submission(s): 66


Problem 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 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

///和 poj 2168 非常类似,坑爹的网络赛
///dp[i][j]为前j个人中,i+1到j为一组时,说真话的最大人数。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=502;
int p[maxn],s[maxn][maxn],dp[maxn][maxn],n;
int main()
{
    while(~scanf("%d",&n))
    {
        memset(dp,0,sizeof(dp));
        memset(p,0,sizeof(p));
        memset(s,0,sizeof(s));
        int i,j,pr,next;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&pr,&next);
            if(pr+next<n) s[pr][next]++;
            if(s[pr][next]>n-pr-next)///预判同一组人数是否符合要求
            {
                s[pr][next]=n-pr-next;
            }
        }
        for(j=1;j<=n;j++)
        {
            for(i=0;i<j;i++)
            {
                dp[i][j]=p[i];
                dp[i][j]+=s[i][n-j];
                if(p[j]<dp[i][j]) p[j]=dp[i][j];
            }
        }
        int ans=0;
        for(i=0;i<n;i++)
        ans=max(ans,dp[i][n]);
        printf("%d\n",ans);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值