hdu1257最少拦截系统

Dilworth定理通俗地讲就是对于一个偏序集,最少链划分等于最长反链长度。

通俗点就是一个数列最少的不上升(<=)子序列的条数等于该数列最长上升(>)子序列的长度

就是求最长有序子序列

package bag;

import java.util.Arrays;
import java.util.Scanner;

public class hdu1257 {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int[] xx = new int[n];
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                xx[i] = sc.nextInt();                
            }
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    if (xx[i] > xx[j]) {
                        if (res[j]+1 > res[i]) {
                            res[i] = res[j]+1;
                        }
                    }                    
                }
                
            }
            Arrays.sort(res);
            System.out.println(res[n-1]+1);
        }
        sc.close();
    }
}

 

posted @ 2024-06-07 22:48  XiaohuangTX  阅读(1)  评论(0编辑  收藏  举报