Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴Java代码。DP O(n*log n)。排行榜前面的大神why能快那么多。。。求指教//LIS import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); for(int i = 0; i < n; i++){ int p = s.nextInt(); int seq[] = new int[p]; int dp[] = new int[p]; for(int j = 0; j < p; j++){ seq[j] = s.nextInt(); dp[j] = 40001; } int len = 0; for(int j = 0; j < p; j++){ int l = 0, r = len; while(l <= r){ int temp = (l+r)/2; if(dp[temp] > seq[j]){ r = temp - 1; }else{ l = temp + 1; } } if(l == len) len++; dp[l] = seq[j]; } System.out.println(len); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator