Groups

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1966    Accepted Submission(s):
778

Problem Description
  After the regional contest, all the ACMers are
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.
 
Input
  There’re several test cases.
  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).
 
Output
  For each test case your program should output a
single integer M, the maximum number of players providing correct
information.
 
Sample Input
3
2 0
0 2
2 2
3
2 0
0 2
2 2
 
Sample Output
2
2

Hint

The third player must be making a mistake, since only 3 plays exist.

 
Source
 
题意:有n个人排成一列,n个人中连续的一排人[i,j](1<=i,j<=n)可能是一组的,也可能不是.现在每个人都会说两个信息,即那个人当前所在组的前面和后面分别有多少人。已知其中有人提供的信息有误。现在要你判断n个人中最多有多少人所给的信息是正确的。
思路:区间dp,dp[i]:前i个人当中最多有多少人说对了。s[i][j]:当以区间[i,j]为一个组时,区间[i,j]内最多有多少人说对了结果。
转移方程为:dp[i]=max(dp[i],dp[j]+s[j+1][i]),即编号到i为止的人当中说对的人的个数可能是由两部分组成:编号到j为止的人当中说对的人的个数+若以[j+1,i]为一组时,该区间内说对结论的人个数。
AC代码:
#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的更多相关文章

  1. HDU 4293 Groups (线性dp)

    OJ题目:click here~~ 题目分析:n个人分为若干组 , 每一个人描写叙述其所在的组前面的人数和后面的人数.求这n个描写叙述中,最多正确的个数. 设dp[ i ] 为前i个人的描写叙述中最多 ...

  2. HDU 4293 Groups

    模型挺好的dp题,其实这道题就是建一个模型然后就很容易想到递推过程了,我们可以把每个人的描述,存到数组a中,a[l][r]表示左边有l个,到第r个这个人所在一层停止...然后就可以写出转移状态方程了. ...

  3. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  4. 转载 - 最短路&差分约束题集

    出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ ...

  5. HDOJ 4751 Divide Groups

    染色判断二分图+补图 比赛的时候题意居然是反的,看了半天样例都看不懂 .... Divide Groups Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  6. 【HDOJ】1669 Jamie's Contact Groups

    二分+二分图多重匹配. /* 1669 */ #include <iostream> #include <string> #include <map> #inclu ...

  7. 【HDOJ】3419 The Three Groups

    记忆化搜索. /* 3419 */ #include <cstdio> #include <cstring> #include <cstdlib> #define ...

  8. iOS: 在iPhone和Apple Watch之间共享数据: App Groups

    我们可以在iPhone和Apple Watch间通过app groups来共享数据.方法如下: 首先要在dev center添加一个新的 app group: 接下来创建一个新的single view ...

  9. [AlwaysOn Availability Groups]AG排查和监控指南

    AG排查和监控指南 1. 排查场景 如下表包含了常用排查的场景.根据被分为几个场景类型,比如Configuration,client connectivity,failover和performance ...

随机推荐

  1. Binary Agents-freecodecamp算法题目

    Binary Agents 1.要求 传入二进制字符串,翻译成英语句子并返回. 二进制字符串是以空格分隔的. 2.思路 用.split(' ')将输入二进制字符串转化为各个二进制数字符串组成的数组 用 ...

  2. 在windows上搭建镜像yum站的方法

    在windows上搭建镜像yum站的方法(附bat脚本)   分类: 运维基本功,其他   方法一:支持rsync的网站 对于常用的centos.Ubuntu.等使用官方yum源在 http://mi ...

  3. 绘制圆形 和 椭圆形:边圆形 imageellipse() 、 填充圆形imagefilledellipse()

    <?php //1. 绘制图像资源(创建一个画布) $image = imagecreatetruecolor(500, 300); //2. 先分配一个绿色 $green = imagecol ...

  4. Python中的dict

    dict_lst = [ ('字典的键必须可哈希',), ('字典的键重复覆盖',), ('字典可迭代') ('增',), ('删',), ('改',), ('查',), ('练习',), ] 字典的 ...

  5. OpenCV学习笔记(四) Mat的简单操作

    转自:OpenCV Tutorial: core 模块. 核心功能 改变图像对比度和亮度:convertTo 可以把  看成源图像像素,把  看成输出图像像素.这样一来,调整亮度和对比度的方法可表示为 ...

  6. python项目中输出指定颜色的日志

    起因 在开发项目过程中,为了方便调试代码,经常会向stdout中输出一些日志,默认的这些日志就直接显示在了终端中.而一般的应用服务器,第三方库,甚至服务器的一些通告也会在终端中显示,这样就搅乱了我们想 ...

  7. 连续小波变换CWT(2)

    如果让你说说连续小波变换最大的特点是什么?多分辨分析肯定是标准答案.所谓多分辨分析即是指小波在不同频率段会有不同的分辨率.具体表现形式,我们回到前一篇文章的第一个图, 图一 对应的信号为 低频时(频率 ...

  8. luogu2023 [AHOI2009]维护序列

    线段树加乘懒标记裸题. #include <iostream> #include <cstdio> using namespace std; typedef long long ...

  9. Sql获取数据表字段说明

    SELECT Sysobjects.name AS TABLE_NAME , syscolumns.Id , syscolumns.name AS COLUMN_NAME , systypes.nam ...

  10. 【Edit Distance】cpp

    题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to w ...