HDU 4293 Groups(dp)
来源:互联网 发布:潘石屹三段婚姻知乎 编辑:程序博客网 时间:2024/05/21 21:40
Groups
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1629 Accepted Submission(s): 618
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.
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).
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
32 00 22 232 00 22 2
Sample Output
22HintThe third player must be making a mistake, since only 3 plays exist.
Source
2012 ACM/ICPC Asia Regional Chengdu Online
题意:有 n 个人,可任意分成若干组,然后每个人各提供一个信息,表示他们组前面有多少个人,后面有多少个人。问最多有多少个信息是不冲突的。
题解:每个人都提供了一个区间[x+1,n-y],dp[i]表示前面i个人不冲突的最大人数。
#include<cstring>#include<algorithm>#include<cstdio>#include<iostream>#include<vector>#define ll long longusing namespace std;int n;int G[555][555],dp[555];struct Jd { int l,r;} ;Jd a[555];bool cmp(Jd a,Jd b) { return a.l<b.l||(a.l==b.r&&a.r<b.r);}int main() { // freopen("test.in","r",stdin); while(~scanf("%d",&n)) { memset(G,0,sizeof G); memset(dp,0,sizeof dp); int x,y,m=0; for(int i=0; i<n; i++) { scanf("%d%d",&x,&y); if(x+y>=n)continue; if(G[x+1][n-y]==0) { a[m].l=x+1; a[m++].r=n-y; } if(n-y-x>G[x+1][n-y]) { G[x+1][n-y]++; } } int k=0; sort(a,a+m,cmp); for(int i = 0; i < m; ++i) { dp[i]=G[a[i].l][a[i].r]; for(int j = 0; j < i; ++j) { if(a[i].l>a[j].r) { dp[i]=max(dp[i],dp[j]+G[a[i].l][a[i].r]); } } } int ans=0; for(int i=0; i<m; i++)ans=max(ans,dp[i]); printf("%d\n",ans); } return 0;}
0 0
- HDU - 4293 Groups (DP)
- HDU 4293 Groups(dp)
- Groups - HDU 4293 dp
- hdu 4293 Groups dp
- HDU 4293 Groups(区间dp)
- HDU 4293 Groups(区间DP)
- HDU 4293 Groups (线性dp)
- HDU 4293 Groups【区间dp】
- hdu 4293 Groups dp 记忆化搜索
- HDU 4293 Groups 区间覆盖 区间DP
- HDU 4293 Groups(12年成都网络赛-F题-DP)
- hdu 4293 Groups(动态规划)
- hdu 4293 Groups
- HDU 4293 Groups
- HDU 4293--Groups
- hdu 4293 Groups
- hdu 4293 Groups
- hdu 4293 Groups
- [iOS开发项目-4] 汤姆猫(只包含动作,没有发声功能)
- css过渡和动画初学
- 安全cookie登录状态设计方案
- 使用VirtualBox + Vagrant打造属于自己的开发环境1
- LintCode -- 不同的子序列
- HDU 4293 Groups(dp)
- 优化LINUX内核阻挡SYN洪水攻击
- c++设计模式-----observer(观察者模式)
- apache双向HTTPS SSL认证配置
- GitHub入门与实践一
- OJ学习笔记2
- [九度OnlineJudge][剑指Offer]题目1387:斐波那契数列
- oracle交流趣事--主机名变更在跑某报告信息时变更的小细节
- 获取当前程序可执行文件的所在路径