hdoj 4293 Groups
Groups
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1966 Accepted Submission(s):
778
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.
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).
single integer M, the maximum number of players providing correct
information.
2 0
0 2
2 2
3
2 0
0 2
2 2
2
The third player must be making a mistake, since only 3 plays exist.
#include <iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<bitset>
#include<cmath>
using namespace std;
#define N_MAX 509
#define INF 0x3f3f3f3f
#define EPS 1e-6
int n;
int dp[N_MAX],s[N_MAX][N_MAX];//s[i][j]:以[i,j]为一组时,这个区间里面最多有几个人说了真话
int main() {
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){//区间[x+1,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;
}
return ;
}
hdoj 4293 Groups的更多相关文章
- HDU 4293 Groups (线性dp)
OJ题目:click here~~ 题目分析:n个人分为若干组 , 每一个人描写叙述其所在的组前面的人数和后面的人数.求这n个描写叙述中,最多正确的个数. 设dp[ i ] 为前i个人的描写叙述中最多 ...
- HDU 4293 Groups
模型挺好的dp题,其实这道题就是建一个模型然后就很容易想到递推过程了,我们可以把每个人的描述,存到数组a中,a[l][r]表示左边有l个,到第r个这个人所在一层停止...然后就可以写出转移状态方程了. ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- 转载 - 最短路&差分约束题集
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★ ...
- HDOJ 4751 Divide Groups
染色判断二分图+补图 比赛的时候题意居然是反的,看了半天样例都看不懂 .... Divide Groups Time Limit: 2000/1000 MS (Java/Others) Memo ...
- 【HDOJ】1669 Jamie's Contact Groups
二分+二分图多重匹配. /* 1669 */ #include <iostream> #include <string> #include <map> #inclu ...
- 【HDOJ】3419 The Three Groups
记忆化搜索. /* 3419 */ #include <cstdio> #include <cstring> #include <cstdlib> #define ...
- iOS: 在iPhone和Apple Watch之间共享数据: App Groups
我们可以在iPhone和Apple Watch间通过app groups来共享数据.方法如下: 首先要在dev center添加一个新的 app group: 接下来创建一个新的single view ...
- [AlwaysOn Availability Groups]AG排查和监控指南
AG排查和监控指南 1. 排查场景 如下表包含了常用排查的场景.根据被分为几个场景类型,比如Configuration,client connectivity,failover和performance ...
随机推荐
- js函数带括号和不带括号赋给对象属性的区别
注意: 1.js为对象添加函数时,不要在函数后面加().一旦加了括号是表示将函数的返回值赋给对象的属性. 例:function test(){ document.writeln("我是js函 ...
- Nginx读书笔记
... upstream proxy_svrs { server http://192.168.1.1:8001/uri/; server http://192.168.1.2:8001/uri/; ...
- TP5数据库操作方法总结
一.TP5数据库操作方法 1.name()方法 作用 : 指定默认的数据表名(不含前缀) 示例 : Db::name('weiba_post'); 返回 : ...
- 数据存储之json文件处理和csv文件处理
什么是json: JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript (w3c制定的js规范)的一个子集,采用 ...
- 单片机入门学习笔记5:STC下载器
STC下载器主要集成了, 1.芯片识别,下载/编程 2.端口识别 3.串口助手 4.KEIL仿真设置 5.芯片选型 6.范例程序 (集成了定时器,串口等例程) 7.波特率计算器 8.定时器计算器 9. ...
- 3 View - 状态保持 session
1.状态保持 http协议是无状态的:每次请求都是一次新的请求,不会记得之前通信的状态 客户端与服务器端的一次通信,就是一次会话 实现状态保持的方式:在客户端或服务器端存储与会话有关的数据 存储方式包 ...
- HDU1042 A * B Problem Plus
A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- mysql之处理金钱小数点后的多余0
问题产生原因:我们在做基金项目 产生大量的金钱 在GP首页展示首页信息的时候要求去除多余的0 由于我们在数据库设计的时候查询返回数据 例如18.100000 这种形式 而我们需要将多余的0 ...
- 设计模式之第16章-代理模式(Java实现)
设计模式之第16章-代理模式(Java实现) “现在朋友圈真是太让人蛋疼了啊.”“怎么说?”“一堆代理,各种卖东西的,看着好烦人.”“哎,删了呗.”“都是朋友,哪里好意思删啊.”“这倒也是...哎,迫 ...
- 3、CSS基础 part-1
1.给body设置颜色 <html> <body text="red"> <p> hello world</p> <p> ...