学习笔记-Dilworth定理

Dilworth定理:我的理解就是,计算给出的一行数字中,连续下降的组数,他会等于最长上升序列的长度。

Dilworth定理 最少的下降序列个数就等于整个序列最长上升子序列的长度

需要注意的是,这个算法只能用来计算,最长上升子序列的长度。

下面代码是从网上参考来的,并不是很懂,求解二分查找是在找什么

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
			int min = Integer.MAX_VALUE;
			int dp[] = new int[100000];  
			int n,x,i;  
			n = cin.nextInt();
			int count = 0;  
			while(n-->0)  {  
				x = cin.nextInt();
				if(count == 0 || dp[count-1] <= x) {
					dp[count++] = x;  
				}
				else  {  
					int low = 0;
					int high = count-1;  
					while(low <= high)  {  
						int mid = (low+high)/2;  
						if(dp[mid] <= x)
							low = mid+1;  
						else
							high = mid-1;  
					}  
					if(dp[low]


你可能感兴趣的:(学习笔记)