标签:
http://acm.hdu.edu.cn/showproblem.php?pid=1025
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 #define N 500005 7 8 int dp[N],road[N]; 9 int x; 10 11 void cal(int a) 12 { 13 int l=1,r=x,mid; 14 while(l<=r){ 15 mid=(l+r)>>1; 16 if(dp[mid]<a) l=mid+1; 17 else r=mid-1; 18 } 19 dp[l]=a; 20 } 21 22 int main() 23 { 24 int n; 25 int cas=0; 26 while(~scanf("%d",&n)){ 27 memset(dp,0,sizeof(dp)); 28 x=1; 29 for(int i=1;i<=n;i++){ 30 int a,b; 31 scanf("%d%d",&a,&b); 32 road[a]=b; 33 } 34 dp[1]=road[1]; 35 for(int i=2;i<=n;i++){ 36 int a=road[i]; 37 if(a>dp[x]) dp[++x]=a; 38 else cal(a); 39 } 40 printf("Case %d:\n",++cas); 41 if(x==1) printf("My king, at most 1 road can be built.\n\n"); 42 else printf("My king, at most %d roads can be built.\n\n",x); 43 } 44 return 0; 45 }
HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)
标签:
原文地址:http://www.cnblogs.com/fightfordream/p/5631935.html