题目链接

http://acm.split.hdu.edu.cn/showproblem.php?pid=4293

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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  4288 4296 4295 4294 4292
 
题意:有n个人走在路上,这些人是分群走的,几个人几个人在一起走,现在对这n个人进行询问,每个人回答在他所在群的前面有多少人,在这个群后面有多少人,求有多少人说了真话(尽可能多的使说真话的人数多)?
 
思路:区间DP,定义dp[i] 表示前i个人中最多有多少人说了真话,s[i][j] 表示第i到第j个人为一群时,i到j最多有多少人说了真话,状态转移方程:dp[i]=dp[j]+dp[j+1][i];
 
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
int dp[]; ///表示i之前说真话的最多人数;
int s[][]; ///表示i到j为一组,组内的人数; int main()
{
int N;
while(scanf("%d",&N)!=EOF)
{
memset(dp,,sizeof(dp));
memset(s,,sizeof(s));
for(int i=;i<N;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(x+y<N&&s[x+][N-y]<N-x-y)
s[x+][N-y]++;
}
for(int i=;i<=N;i++)
{
for(int j=;j<i;j++)
{
dp[i]=max(dp[i],dp[j]+s[j+][i]);
}
}
cout<<dp[N]<<endl;
}
}
/*
3
2 0
0 2
2 2
*/

HDU 4293---Groups(区间DP)的更多相关文章

  1. HDU 4293 Groups (线性dp)

    OJ题目:click here~~ 题目分析:n个人分为若干组 , 每一个人描写叙述其所在的组前面的人数和后面的人数.求这n个描写叙述中,最多正确的个数. 设dp[ i ] 为前i个人的描写叙述中最多 ...

  2. hdu 5396 Expression(区间dp)

    Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...

  3. You Are the One HDU - 4283 (区间DP)

    Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...

  4. Dire Wolf HDU - 5115(区间dp)

    Dire Wolf Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)Total ...

  5. HDU 5568 sequence2 区间dp+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...

  6. hdu 4579 博弈+区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...

  7. HDU 4293 Groups

    模型挺好的dp题,其实这道题就是建一个模型然后就很容易想到递推过程了,我们可以把每个人的描述,存到数组a中,a[l][r]表示左边有l个,到第r个这个人所在一层停止...然后就可以写出转移状态方程了. ...

  8. Hdu 2513 区间DP

    Cake slicing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  9. HDU 4283---You Are the One(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4283 Problem Description The TV shows such as Y ...

随机推荐

  1. Node.js与Sails~Model数据模型

    回到目录 对于Sails来说,它的Model与数据库对应,不过它并没有采用目前比较流行的poco贫血模型,而是采用了类似DDD的充血模型,即它的数据实体里即有数据库字段(属性)而且还有方法,而模型里的 ...

  2. lua的table表处理 及注意事项

    lua,一款很轻量级很nice很强大的脚本语言,做为lua中使用最为频繁的table表,在使用之时还是有颇多的好处与坑的: 下面是大牛 云风的一片关于lua table的blog,可使得对lua ta ...

  3. Spring-JDBC实现Contact的CRUD

    Spring-JDBC完成Contact的CRUD. 两点注意: 1.log4j.properties文件不能少 2.注意导入的包之间的依赖关系以及版本要求. 项目结构: 主要文件: 建表脚本: CR ...

  4. BrowserSync前端调试工具使用

    上次介绍了一款DebugGap移动端调试工具DebugGap推荐.但是这几天使用了之后感觉还是有些不足,尤其是里面的调试工具虽然和Chrome里面的调试长的很像,但是多少有些不同,使用起来还是不太方便 ...

  5. 【技巧】只利用 Visual Stdio 自带的工具这么找父类?

    很多人说只能 F12 看见子类 其实vs里面有一个叫“对象浏览器” 通过这个就可以直接定位父类,不需要利用reflector之类的工具来找父类 具体如下:

  6. 找到SQL Server数据库历史增长信息

        很多时候,在我们规划SQL Server数据库的空间,或向存储方面要空间时,都需要估算所需申请数据库空间的大小,估计未来最简单的办法就是看过去的趋势,这通常也是最合理的方式.     通常来讲 ...

  7. vs xamarin android 读取rest

    private void Btn_Click(object sender, EventArgs e) { var u = FindViewById<EditText>(Resource.I ...

  8. Mybatis之Oracle增删查改示例--转

    http://blog.csdn.net/bingjie1217/article/details/21088431?utm_source=tuicool&utm_medium=referral ...

  9. HTML5移动Web开发(四)——移动设计

    桌面网站的设计趋势是固定布局(fixed layout)或流体布局(fluid layout),而在移动网站中我们应该始终使用流体布局,它可以使你的网站适应不同的设备尺寸. 固定宽度布局(Fixed ...

  10. Oracle数据库常见的误操作恢复方法(上)

    实验环境:Linux6.4 + Oracle 11g 面向读者:Oracle开发维护人员 概要: 1.误操作drop了emp表 2.误操作delete了emp表 3.误操作delete了emp表的部分 ...