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 ...
随机推荐
- Binary Agents-freecodecamp算法题目
Binary Agents 1.要求 传入二进制字符串,翻译成英语句子并返回. 二进制字符串是以空格分隔的. 2.思路 用.split(' ')将输入二进制字符串转化为各个二进制数字符串组成的数组 用 ...
- 在windows上搭建镜像yum站的方法
在windows上搭建镜像yum站的方法(附bat脚本) 分类: 运维基本功,其他 方法一:支持rsync的网站 对于常用的centos.Ubuntu.等使用官方yum源在 http://mi ...
- 绘制圆形 和 椭圆形:边圆形 imageellipse() 、 填充圆形imagefilledellipse()
<?php //1. 绘制图像资源(创建一个画布) $image = imagecreatetruecolor(500, 300); //2. 先分配一个绿色 $green = imagecol ...
- Python中的dict
dict_lst = [ ('字典的键必须可哈希',), ('字典的键重复覆盖',), ('字典可迭代') ('增',), ('删',), ('改',), ('查',), ('练习',), ] 字典的 ...
- OpenCV学习笔记(四) Mat的简单操作
转自:OpenCV Tutorial: core 模块. 核心功能 改变图像对比度和亮度:convertTo 可以把 看成源图像像素,把 看成输出图像像素.这样一来,调整亮度和对比度的方法可表示为 ...
- python项目中输出指定颜色的日志
起因 在开发项目过程中,为了方便调试代码,经常会向stdout中输出一些日志,默认的这些日志就直接显示在了终端中.而一般的应用服务器,第三方库,甚至服务器的一些通告也会在终端中显示,这样就搅乱了我们想 ...
- 连续小波变换CWT(2)
如果让你说说连续小波变换最大的特点是什么?多分辨分析肯定是标准答案.所谓多分辨分析即是指小波在不同频率段会有不同的分辨率.具体表现形式,我们回到前一篇文章的第一个图, 图一 对应的信号为 低频时(频率 ...
- luogu2023 [AHOI2009]维护序列
线段树加乘懒标记裸题. #include <iostream> #include <cstdio> using namespace std; typedef long long ...
- Sql获取数据表字段说明
SELECT Sysobjects.name AS TABLE_NAME , syscolumns.Id , syscolumns.name AS COLUMN_NAME , systypes.nam ...
- 【Edit Distance】cpp
题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to w ...