HDU 4293---Groups(区间DP)
题目链接
http://acm.split.hdu.edu.cn/showproblem.php?pid=4293
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.
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).
The third player must be making a mistake, since only 3 plays exist.
#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)的更多相关文章
- HDU 4293 Groups (线性dp)
OJ题目:click here~~ 题目分析:n个人分为若干组 , 每一个人描写叙述其所在的组前面的人数和后面的人数.求这n个描写叙述中,最多正确的个数. 设dp[ i ] 为前i个人的描写叙述中最多 ...
- hdu 5396 Expression(区间dp)
Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...
- 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 ...
- Dire Wolf HDU - 5115(区间dp)
Dire Wolf Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total ...
- HDU 5568 sequence2 区间dp+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...
- hdu 4579 博弈+区间dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...
- HDU 4293 Groups
模型挺好的dp题,其实这道题就是建一个模型然后就很容易想到递推过程了,我们可以把每个人的描述,存到数组a中,a[l][r]表示左边有l个,到第r个这个人所在一层停止...然后就可以写出转移状态方程了. ...
- Hdu 2513 区间DP
Cake slicing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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 ...
随机推荐
- asp.net 有关时间各种(输出)处理
有关一下时间处理方法 /// <summary> /// 将时间转换成几小时.几天之类的格式 /// </summary> /// <param name="m ...
- Python的枚举类型
Python的 Python的没有我们有两种用法: 创建Enum的实例 创建Enum的subclass 创建Enum的实例 from enum import Enum, unique Month = ...
- OOM异常产生的原因和处理方法
一般而言,android中常见的原因主要有以下几个: 1.数据库的cursor没有关闭. 2.构造adapter没有使用缓存contentview. 3.调用registerReceiver()后未调 ...
- leancloud 用户登录(调用API) 教程
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; ...
- 领会CSS,实际中的研究
虽懂却不会,真是可怕,自认懂却了无. 善用CSS属性选择器 在用于区别和唯一的情况下完全可以使用属性选择器,而没有必要使用class或id p[city="http://www.css.co ...
- Android入门(十四)内容提供器-实现跨程序共享实例
原文链接:http://www.orlion.ga/661/ 打开SQLite博文中创建的 DatabaseDemo项目,首先将 MyDatabaseHelper中使用 Toast弹出创建数据库成功的 ...
- JUnit4使用
1.导入Junit4jar包: Eclipse中在项目上右键点击Bulid Path,然后再点击Add libraries,选择JUnit 2.初次使用 首先先创建一个java项目如下: Demo.j ...
- java中包容易出现的错误及权限问题
/* 3,权限在不同地方的体现: public protected default private 同一类中: ok ok ok ok 同一包中: ok ok ok 子类中: ok ok 不同包中: ...
- 如何用Python寻找重复文件并删除
在实际生活中,经常会有文件重复的困扰,即同一个文件可能既在A目录中,又在B目录中,更可恶的是,即便是同一个文件,文件名可能还不一样.在文件较少的情况下,该类情况还比较容易处理,最不济就是one by ...
- tomcat server容器解读
1. server的实例类为:org.apache.catalina.core.StandardServer为顶层容器. 2.二级容器GlobalNamingResources,设置认证用户信息. & ...