DP_简单DP最长上升子序列[n*lg(n)](HDU_1025)
^_^
#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; }