其他分享
首页 > 其他分享> > AcWing 300. 任务安排1

AcWing 300. 任务安排1

作者:互联网

题目链接

https://www.acwing.com/problem/content/302/

题解

AC代码

import java.util.*;

public class Main {
    static int N = 5010;
    static int[] sumT = new int[N], sumC = new int[N];
    static long[] f = new long[N];
    static int n, s;
    
    public static void main(String[] args) {
        Scanner sc =  new Scanner(System.in);
        n = sc.nextInt();
        s = sc.nextInt();
        for (int i = 1; i <= n; i ++) {
            sumT[i] = sumT[i - 1] + sc.nextInt();
            sumC[i] = sumC[i - 1] + sc.nextInt();
        }
        
        Arrays.fill(f, Long.MAX_VALUE);
        f[0] = 0;
        for (int i = 1; i <= n; i ++) 
            for (int j = 0; j < i; j ++) 
                f[i] = Math.min(f[i], f[j] + s * (sumC[n] - sumC[j]) + (long) sumT[i] * (sumC[i] - sumC[j]));
                
        System.out.println(f[n]);
    }
}

标签:nextInt,300,安排,long,int,static,sc,new,AcWing
来源: https://www.cnblogs.com/doubest/p/16388712.html