hdu1025 LIS
来源:互联网 发布:淘宝助理如何在线发货 编辑:程序博客网 时间:2024/05/21 20:25
题目链接:点击打开链接
题目是给你匹配对,第i个穷人城市需要第j个富人城市的帮助,穷人与富人城市是平行线,要求不能有交叉,比如1—>2,2->1是不行的,求最多能被帮助的城市数量。
思路:可看成LIS问题。
代码是别人的模板代码
#include <iostream>#include<cstdio>using namespace std;const int maxn=500000+10;int Arr[maxn],List[maxn];int Stack[maxn];int LIS(int *Arr,int N){ int top = 0; Stack[top] = -1; for(int i = 1; i <= N; ++i) { if(Arr[i] > Stack[top]) Stack[++top] = Arr[i]; else { int low = 1; int high = top; while(low <= high) { int mid = (low + high)/2; if(Arr[i] > Stack[mid]) low = mid + 1; else high = mid - 1; } Stack[low] = Arr[i]; } } return top;}int main(){ int ans,i,j,n,a,b; ans=0; while(~scanf("%d",&n)) { for(i=0;i<n;i++) { scanf("%d %d",&a,&b); Arr[a]=b; } int k=LIS(Arr,n); if(k==1) printf("Case %d:\nMy king, at most %d road can be built.\n\n",++ans,k); else printf("Case %d:\nMy king, at most %d roads can be built.\n\n",++ans,k); } return 0;}
阅读全文
0 0
- hdu1025 LIS
- hdu1025 - LIS
- hdu1025 LIS
- 【dp:LIS】hdu1025
- HDU1025 nlogn的LIS
- hdu1025
- HDU1025
- hdu1025
- hdu1025
- hdu1025
- HDU1025
- HDU1025:Constructing Roads In JGShining's Kingdom(LIS)
- hdu1025 Constructing Roads In JGShining's Kingdom (nlogn的LIS)
- HDU1025:Constructing Roads In JGShining's Kingdom(LIS(dp+二分))
- HDU1025 Constructing Roads In JGShining's Kingdom (LIS)
- LIS
- LIS
- LIS
- 输入输出挂
- NAND flash和NOR flash的区别
- MySql基础教程二(视图,存储过程,游标,触发器,事务,权限,数据类型)
- 最小环flody hdu6080
- Android webview 踩坑经验总结
- hdu1025 LIS
- Enum使用
- hbase性能调优
- ios-多线程访问共享资源
- Binary Protocol (Codeforces
- java之static语法详解
- UVA
- WPF布局篇(三)
- 企业数据分析,搞定这3个重点事半功倍!