HDOJ 4293 Groups
来源:互联网 发布:淘宝网企业注册流程 编辑:程序博客网 时间:2024/06/15 06:46
水DP。。。
Groups
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1133 Accepted Submission(s): 440
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.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n,dp[550],p[550][550];int main(){while(scanf("%d",&n)!=EOF){int a,b;memset(dp,0,sizeof(dp));memset(p,0,sizeof(p));for(int i=0;i<n;i++) {scanf("%d%d",&a,&b);int st=a+1,ed=n-b;p[st][ed]=min(p[st][ed]+1,ed-st+1);}for(int i=1;i<=n;i++){for(int j=0;j<i;j++){dp[i]=max(dp[i],dp[j]+p[j+1][i]);}}printf("%d\n",dp[n]);}return 0;}
1 0
- HDOJ 4293 Groups
- HDOJ 4751 Divide Groups
- HDOJ 4293暨The 37th ACM/ICPC Asia Regional ChengDu Site Online Contest - F Groups
- HDOJ 4751 - Divide Groups 暴力DFS
- HDOJ-----4751---Divide Groups二分判断
- hdu 4293 Groups
- HDU 4293 Groups
- HDU 4293--Groups
- hdu 4293 Groups
- hdu 4293 Groups
- hdu 4293 Groups
- hdu 4293 Groups
- hdu 4293 Groups
- HDU 4293 Groups
- HDU 4293 Groups
- Groups - HDU 4293 dp
- hdu 4293 Groups dp
- Groups
- 何为挂载?
- Linux常见问题处理方法
- HTTP状态管理
- 华为练习2 查找兄弟单词
- C++中引用传递与指针传递区别
- HDOJ 4293 Groups
- HTTP认证教程(四)
- 进阶
- HTTP客户端服务
- Freemarker中如何遍历list
- 项目管理---敏捷开发---到底要不要写文档?
- HTTPClient六 高级主题
- hdu 1695 容斥原理或莫比乌斯反演
- 最小生成树(模板)