标签:des style blog http color io os java ar
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16047 Accepted Submission(s): 4580
1 //#define LOCAL 2 #include<cstdio> 3 #include<cstring> 4 const int maxn=50005; 5 const int inf=0x3f3f3f3f; 6 int str[maxn],dp[maxn],sac[maxn]; 7 int res; 8 9 int binary(int v,int n) 10 { 11 int ll=1,rr=n,mid; 12 while(ll<=rr) 13 { 14 mid=ll+(rr-ll)/2; 15 if(sac[mid]<=v&&sac[mid]!=-1) 16 ll=mid+1; 17 else 18 rr=mid-1; 19 } 20 return ll; 21 } 22 void LIS(int n) 23 { 24 res=1; 25 // for(int i=1;i<=n;i++) 26 // sac[i]=inf; 27 memset(sac,-1,sizeof(int)*(n+1)); 28 for(int i=1;i<=n;i++) 29 { 30 dp[i]=binary(str[i],res); 31 if(res<dp[i]) 32 res=dp[i]; 33 if(str[i]<sac[dp[i]]||sac[dp[i]]==-1) 34 sac[dp[i]]=str[i]; 35 } 36 } 37 int main() 38 { 39 #ifdef LOCAL 40 freopen("test.in","r",stdin); 41 #endif 42 43 int n,i,p,r,ct=1; 44 while(scanf("%d",&n)!=EOF) 45 { 46 for( i=1;i<=n;i++){ 47 scanf("%d%d",&p,&r); 48 str[p]=r; 49 } 50 LIS(n); 51 printf("Case %d:\n",ct++); 52 if(res==1) 53 printf("My king, at most 1 road can be built.\n"); 54 else 55 printf("My king, at most %d roads can be built.\n",res); 56 printf("\n"); 57 } 58 return 0; 59 }
hdu--(1025)Constructing Roads In JGShining's Kingdom(dp/LIS+二分)
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3992758.html