DP_简单DP最长上升子序列[n*lg(n)](HDU_1025)
2013-08-13 13:35
387 查看
^_^
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define M 500002 int mu[M],d[M]; int lis(int n) //n*lg(n) { d[1] = mu[1]; int len = 1; for(int i=2; i<=n; i++) { int l = 1,r = len; while(l <= r) { int mid = (l + r) >> 1; if(d[mid] < mu[i]) l = mid + 1; else r = mid - 1; } d[l] = mu[i]; if(l > len) len++; } return len; } int main(int argc, char* argv[]) { #ifdef __MYLOCAL freopen("in.txt","r",stdin); #endif int n,t=1,len; while(scanf("%d",&n) != EOF) { for(int i=1; i<=n; i++) { int cur,in; scanf("%d%d",&cur,&in); mu[cur] = in; } len = lis(n); printf("Case %d:\n",t++); printf("My king, at most %d %s can be built.\n\n",len,len==1 ? "road" : "roads"); } return 0; }
相关文章推荐
- HDU 1025 Constructing Roads In JGShining's Kingdom (简单dp, 最长上升子序列LIS)
- 【DP】HDU 1025 Constructing Roads In JGShining's Kingdom 最长上升子序列
- HDU 1257 最少拦截系统(最长上升子序列 动态规划(DP))
- hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升序列n*logn算法)
- 关于最长上升子序列的算法 简单dp
- 暑期dp46道(16)hdoj 1025 Constructing Roads In JGShining's Kingdom最长上升子序列(二分)
- HDU 1160 FatMouse's Speed 最长上升子序列 简单DP
- HDU-1257 最少拦截系统 贪心/DP 最长上升子序列的长度==最长不上升子序列的个数?
- HDU 1025 最长上升子序列变形 (dp+二分)
- HDU 1025 Constructing Roads In JGShining's Kingdom(DP,LIS最长上升子序列)
- HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列的长度)
- 动态规划之编号动态规划:hdu 1025(dp+二分 求最长上升子序列)
- 最长上升子序列(LIS)(HDU 1025)
- hdu 1025 Constructing Roads In JGShining's Kingdom 最长上升序列nlogn
- hdu 1069 Monkey and Banana(类似最长上升子序列,dp)
- hdu,1025 dp求最长递增序列。
- hdu 1025 Constructing Roads In JGShining's Kingdom 最长上升序列
- hdu 1025 Constructing Roads In JGShining's Kingdom 最长上升序列nlogn
- HDU 1025 高效最长上升子序列(二分查)
- hdu 1025 Constructing Roads In JGShining's Kingdom 深夜又一波DP,最长上升子序列(O(nlogn)算法)!尼玛坑爹的输出啊!!