poj 3171Cleaning Shifts 区间覆盖

这个区间覆盖很明显是DP

一般的N平方是过不去的。看了下题解,只能搜到些线段树+dp的,但是很明显我根本不会线段树。

然后强行N平方的DP加了好几个剪枝,主要是这个index数组使得更新数组的时候可以跳一大截,于是居然刷到了java类最快的速度。。。汗

/*
ID: daniel.20
LANG: JAVA
TASK: tour
 */

import java.util.*;
import java.io.*;

class cow implements Comparable{
    int a,b,c;
    public cow(int x,int y,int z){
        a=x;b=y;c=z;
    }
    @Override
    public int compareTo(cow t) {
        if(this.a==t.a){
            if(this.b==t.b) return this.c-t.c;
            else return t.b-this.b;
        }
        return this.a-t.a;
    }
}
class pb1{
    int n,m,e;
    cow arr[];
    long table[];
    int index[];
    void solver() throws IOException{
        //Scanner scan = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(reader.readLine());
        n = Integer.parseInt(st.nextToken());
        m = Integer.parseInt(st.nextToken())+1;
        e = Integer.parseInt(st.nextToken())+1;
        arr = new cow[n+1];
        table = new long[e+1];
        index = new int[e+1];
        for(int i=1;i<=n;i++) {
            st = new StringTokenizer(reader.readLine());
            int t1 = Integer.parseInt(st.nextToken())+1;
            int t2 = Integer.parseInt(st.nextToken())+1;
            int t3 = Integer.parseInt(st.nextToken());
            arr[i] = new cow(t1,t2,t3);
        }
        Arrays.sort(arr,1,n+1);
        Arrays.fill(table, Long.MAX_VALUE);
        for(int i=0;i=max_c) continue;
            if(arr[i].b>max_r&&arr[i].c>max_c) {max_r=arr[i].b;max_c=arr[i].c;}
            long tmp = table[arr[i].a-1]+arr[i].c;
            for(int k=arr[i].a;k<=arr[i].b;k++){
                if(table[k]>tmp) {table[k]=tmp; index[k]=i;}
                else if(k


你可能感兴趣的:(POJ,DP)