HDU 4293---Groups(区间DP)
2018-06-17 23:49:14来源:未知 阅读 ()
题目链接
http://acm.split.hdu.edu.cn/showproblem.php?pid=4293
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).
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <set> using namespace std; int dp[505]; ///表示i之前说真话的最多人数; int s[505][505]; ///表示i到j为一组,组内的人数; int main() { int N; while(scanf("%d",&N)!=EOF) { memset(dp,0,sizeof(dp)); memset(s,0,sizeof(s)); for(int i=0;i<N;i++) { int x,y; scanf("%d%d",&x,&y); if(x+y<N&&s[x+1][N-y]<N-x-y) s[x+1][N-y]++; } for(int i=1;i<=N;i++) { for(int j=0;j<i;j++) { dp[i]=max(dp[i],dp[j]+s[j+1][i]); } } cout<<dp[N]<<endl; } } /* 3 2 0 0 2 2 2 */
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash