hdu1025 超经典最长上升子序问题
来源:互联网 发布:数据库系统工程师希赛 编辑:程序博客网 时间:2024/06/14 17:33
/* 2015.11.16 1025.最长上升自序问题 n(1 ≤ n ≤ 500,000) Sample Input21 22 131 22 33 1Sample OutputCase 1:My king, at most 1 road can be built.Case 2:My king, at most 2 roads can be built.*/#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <algorithm>const int MAX = 500005;const int INF = 5000000;using namespace std;int arr[MAX];int solve[MAX];int solveQ(int n){ int fir, sec; for(int i=0; i<n; i++){ solve[i] = INF; } for(int i=1; i<=n; i++){ scanf("%d%d", &fir, &sec); arr[fir] = sec; } for(int i=1; i<=n; i++){ *lower_bound(solve,solve+n, arr[i]) = arr[i]; } return lower_bound(solve, solve+n,INF) - solve;}int main(){ int n, ans; int i=1; while(scanf("%d", &n)!=EOF){ ans = solveQ(n); printf("Case %d:\n", i++); if(ans == 1){ printf("My king, at most 1 road can be built.\n\n"); }else{ printf("My king, at most %d roads can be built.\n\n", ans); } } return 0;}/* 具体解体思路见挑战程序设计竞赛中P65页,很经典。 另,该题有坑。 1.如果结果是1,则单词road应为单数,反之为复数。 2.一句话结束后有两个回车。*/
0 0
- hdu1025 超经典最长上升子序问题
- hdu1025(最长上升子序列)
- hdu1025 最长上升子序列
- HDU1025 最长上升子序列
- 最长上升子序列--poj2533、poj3903、hdu1025
- hdu1025(最长上升子序列)
- hdu1025(最长上升子序列)
- HDU1025 最长上升子序列(nlogn算法) DP
- hdu1025!求最长上升子序列的另种方法!!!!
- hdu1025最长上升子序列 (加二分优化)
- hdu1025 (最长上升子序列n*logn)
- hdu1025 最长上升子序列 O(nlogn)优化版
- 经典动态规划问题--最长上升子序列 POJ--2533
- 动态规划经典问题 最长上升子序列poj2533
- 最长上升子序列问题
- 最长上升子序列问题
- 最长上升子序列问题
- 最长上升子序列问题
- 请求解析数据 SDWebImage请求图片
- 【黑马程序员】抽象类、接口和内部类
- 转载:警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting
- 集合运算(UNION、UNION ALL、INTERSECT、MINUS)
- 基类 派生类 静态查找表
- hdu1025 超经典最长上升子序问题
- ARC小结
- Lowest Bit
- 定位-01-定位服务编程
- JS异步模式与Promise模式
- Struts2 关于i18n国际化的问题,可点击链接实现中英文切换
- 错误"failed to push some refs to"的解决办法
- Android APK反编译就这么简单 详解(附图)
- ubuntu 安装新软件后利用export设计PATH重启依旧有效方法