1. 程式人生 > >Open cup #2

Open cup #2

最小 ans turn class ast ret strong init div

A

D:用前面的H去消去後面的K 然後求最長連續的M

F:在每一列/行裏面求最大的數然後組成最大的和ans[]裏的比求出最大的

L:並查集

J:DP背鍋題 01背包 先求出M種裏每種的size和last然後先last最大的放在最後 然後背包DP

long long solve(Group* groups) {
    long long* x = new long long[n + 1];
    for (int i=0; i<n+1; i++) x[i] = INFINITY;
    x[0] = 0;

    // all groups but the last; the last always goes
    
// into "last" bus for (int i=0; i<m-1; i++) for (int j=n-groups[i].size; j>=0; j--) { long long time = max(x[j], groups[i].time); x[j+groups[i].size] = min(time, x[j+groups[i].size]); } //for (int i=0; i<=n; i++) cout << x[i] << " ";
//cout << endl; long long answer = -1; for (int i=0; i<=k; i++) if (n - i <= k) if (x[i] < INFINITY) { long long total = x[i] * i + (n - i) * groups[m-1].time; if (answer == -1 || total < answer) answer = total; }
return answer; }

X[i]表示有i人在一個飛機上時的最小last

然後i從0枚舉到k如果剩下的不大於K就統計total 更新答案

Open cup #2