hdu 4293 poj 2168 dp
来源:互联网 发布:装修设计软件哪个好 编辑:程序博客网 时间:2024/06/05 13:35
Groups
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 153 Accepted Submission(s): 66
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
///和 poj 2168 非常类似,坑爹的网络赛///dp[i][j]为前j个人中,i+1到j为一组时,说真话的最大人数。#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int maxn=502;int p[maxn],s[maxn][maxn],dp[maxn][maxn],n;int main(){ while(~scanf("%d",&n)) { memset(dp,0,sizeof(dp)); memset(p,0,sizeof(p)); memset(s,0,sizeof(s)); int i,j,pr,next; for(i=1;i<=n;i++) { scanf("%d%d",&pr,&next); if(pr+next<n) s[pr][next]++; if(s[pr][next]>n-pr-next)///预判同一组人数是否符合要求 { s[pr][next]=n-pr-next; } } for(j=1;j<=n;j++) { for(i=0;i<j;i++) { dp[i][j]=p[i]; dp[i][j]+=s[i][n-j]; if(p[j]<dp[i][j]) p[j]=dp[i][j]; } } int ans=0; for(i=0;i<n;i++) ans=max(ans,dp[i][n]); printf("%d\n",ans); } return 0;}
- hdu 4293 poj 2168 dp
- HDU POJ 数位DP
- POJ 1260 && HDU 1300 DP
- POJ 1185 HDU 4539 状态压缩DP
- hdu 2713 (水dp)|| poj 2181
- POJ 3486 & HDU 1913 Computers(dp)
- Coins (poj 1742 && hdu 2844 DP)
- 区间DP poj 2955 hdu 2476
- POJ 1260 && HDU 1300 Pearls(dp)
- HDU 1300 POJ 1260 Pearls (DP)
- hdu 1502 , poj 1463, hdu 1561 树形dp
- hdu 4293 区间dp
- Groups - HDU 4293 dp
- hdu 4293 Groups dp
- POJ 3345 HDU 2415 Bribing FIPA(树形DP)
- poj 2411/hdu 1400 Mondriaan's Dream 状态压缩dp
- POJ 2342 & HDU 1520 Anniversary party (树形DP)
- HDU 1501 & POJ 2192 Zipper(dp记忆化搜索)
- Android2.3 Ethernet Framework 移植(一)
- iOS开发笔记--Run Loops
- javax.servlet.ServletException: DispatchMapping[XXX] does not define a handler property
- 青春划过指尖
- 使用TCP连续传输文件的问题解决
- hdu 4293 poj 2168 dp
- 最新电子研发活动
- JS实现字体选色板
- WeakHashMap的神话
- openOffice+pdf2swf+flexpaper(类百度文库) :office转pdf(Linux,window)
- 将本地开发的 Maven 2 项目部署到 Linux Tomcat 下的步骤
- 2012年9月17日Axure RP Pro 6.5.0.3037 Windows正體中文加強正式版進展
- eclipse中js报错的解决方法,100%有效
- iPhone应用程序委托