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 ...
随机推荐
- servlet从服务器磁盘文件读出到浏览器显示,中文乱码问题,不要忘记在输入流和输出流都要设置编码格式,否则一个地方没设置不统一就会各种乱码
package com.swift; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOE ...
- jpeg解码库使用实例
jpeg库下载地址: http://www.ijg.org/ 交叉编译三部曲: A ./configure --host=arm-linux-gcc --prefix=/home/flying/jpe ...
- SpringBoot之自动配置原理
我在前面的Helloworld的程序中已经分析过一次,配置原理了: 1).SpringBoot启动的时候加载主配置类,开启了自动配置功能 @EnableAutoConfiguration 2).@En ...
- DNS服务初步搭建
一.准备DNS服务环境 选择 bind dns服务软件包 直接yum安装 bind 和 bind-utils 工具包,测试机器安装bind-utils测试工具包. 服务程序名为 named 二.配置D ...
- nginx负载均衡集群(二)
nginx负载均衡配置实战 一.配置基于域名虚拟主机的web节点 web02和web01做同样的操作,nginx配置文件如下: [root@web01 conf]# cat nginx.conf wo ...
- Yii2.X 如何避开pathinfo不能处理中文名开头的bug
/** * @return string original file base name */ public function getBaseName() { // https://github.co ...
- win7旗舰版64位java的jdk环境变量的配置(2012-12-26-bd 写的日志迁移
首先到oracle的官方网站http://www.oracle.com/technetwork/cn/java/javase/downloads/index.html下个JDK比如下图: 必须是win ...
- Java List 的深拷贝
老是会遇到深拷贝与浅拷贝的问题,这里进行了一些測试.代码例如以下: </pre><pre name="code" class="java"&g ...
- 4 Values whose Sum is 0 POJ - 2785
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 29243 Accep ...
- Win7系统桌面便签怎么添加?
参考:http://jingyan.baidu.com/article/ab69b270c207432ca7189f99.html Win7系统桌面便签怎么添加?有时候工作.学习忙起来就会忘记要办的事 ...