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 ...
随机推荐
- question 002: dev c++ 当中如何调整字体大小?How to get the first program with C++? c++属于什么软件?
方法:按住ctrl+鼠标滑轮滚动 c++属于系统软件还是应用软件? 说哪个都不对,编译之前属于应用软件,after compile ,it belongs to system software. #i ...
- Python 一行代码输出心形图案
Python3 >>> print('\n'.join([''.join([('Love'[(x-y)%4]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0. ...
- linux下通过phpize为php在不重新编译php情况下安装模块memcache
通过phpize为php在不重新编译php情况下安装模块memcache 1. 下载 wget http://pecl.php.net/get/memcache-2.2.4.tgz 解压 ...
- 抽象类&接口区别
抽象类:1.可以有构造方法. 2.可以有抽象方法也可以有具体方法. 3.权限修饰符可以是private.默认.protected.public. 4.可以定义成员变量. 5.interface ...
- 1- vue django restful framework 打造生鲜超市
Vue+Django REST framework实战 使用Python3.6与Django2.0.2(Django-rest-framework)以及前端vue开发的前后端分离的商城网站 项目支持支 ...
- vue layui
关于 vue中使用layui插件,个人一些小小的心得. 我是全局的引入,在static文件夹里存放layui的完整代码 在index页面中标签引入 <link rel="stylesh ...
- python3.7 sys模块
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 sys模块 #sys模块负责程序与python解释器的交互,提供 ...
- 2、python中的数字
第二篇开始谈谈python中的数据. 一.前言 python中的数字包含了整数.浮点数.复数三种.在python的早期版本,或许可以看到正数被分为长整数与短整数,后来被取消了,因此这里不作讨论.通常我 ...
- TCP/IP网络编程之基于TCP的服务端/客户端(一)
理解TCP和UDP 根据数据传输方式的不同,基于网络协议的套接字一般分为TCP套接字和UDP套接字.因为TCP套接字是面向连接的,因此又称为基于流(stream)的套接字.TCP是Transmissi ...
- pycharm的常用操作:设置字体主题,注释整段代码,调整格式,批量替换等
1.调出常用工具栏 调出的结果是下面这样的: 2.调出常用工具按钮 调出的结果如下: 3. 调整主题及文字大小 ps:如果设置后没变,需要多设置几次就好了. 4. 统一后退几格调整对齐格式 选中要调整 ...