标签:des style blog http color io os java ar
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 667 Accepted Submission(s): 443
1 //#define LOCAL 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<iostream> 6 #define inf 0x3f3f3f3f 7 using namespace std; 8 const int maxn=40005; 9 10 int str[maxn],ans[maxn],dp[maxn]; 11 int n,dd; 12 13 int LIS(int a[], int n) 14 { 15 int i, j,res=0; 16 for(i=1;i<=n;i++) 17 ans[i]=inf; 18 memset(dp,0,sizeof(int)*(n+1)); 19 for(i=1;i<=n;++i) 20 { 21 22 dp[i]=lower_bound(ans+1,ans+n+1,a[i])-ans; 23 // j=bsearch(c, size, a[i]); //在已有的序列中进行替换 24 if(res<dp[i])res=dp[i]; 25 j=i; 26 if(j>0&&ans[dp[j]]>a[j]) 27 ans[dp[j]]=a[j]; 28 } 29 return res; 30 } 31 32 33 int main() 34 { 35 #ifdef LOCAL 36 freopen("test.in","r",stdin); 37 #endif 38 int cas; 39 scanf("%d",&cas); 40 while(cas--){ 41 42 scanf("%d",&n); 43 for(int i=1;i<=n;i++) 44 { 45 scanf("%d",str+i); 46 } 47 printf("%d\n",LIS(str,n)); 48 } 49 return 0; 50 }
hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3991605.html