Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴Java代码。DP O(n*log n)。排行榜前面的大神why能快那么多。。。求指教

Posted by haqishen at 2015-01-04 14:22:25 on Problem 1631 and last updated at 2015-01-04 14:22:51
//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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator