bzoj 1222

想了一个小时。。

思路:dp[ i ] 表示第一台机器用了 i 分钟 第二台机器所用的最少分钟数,然后转移一下就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> >

using namespace std;

const int N = 1e5 + 10;
const int M = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;

int n, dp[2][30100], cur;
int main() {
    memset(dp, inf, sizeof(dp));
    int up = 0, nx_up = 0;
    dp[cur][0] = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        cur ^= 1;
        swap(up, nx_up);

        for(int i = 0; i <= up + 5; i++)
            dp[cur][i] = inf;

        int t1, t2, t3;
        scanf("%d%d%d", &t1, &t2, &t3);
        nx_up = up;
        for(int j = 0; j <= up; j++) {
            if(t1) dp[cur][j + t1] = min(dp[cur][j + t1], dp[cur ^ 1][j]);
            if(t2) dp[cur][j] = min(dp[cur][j], dp[cur ^ 1][j] + t2);
            if(t3) dp[cur][j + t3] = min(dp[cur][j + t3], dp[cur ^ 1][j] + t3);
            nx_up = max(nx_up, j + t1);
            nx_up = max(nx_up, j + t3);
        }
    }

    int ans = inf;
    for(int i = 0; i <= nx_up; i++)
        ans = min(ans, max(i, dp[cur][i]));

    printf("%d
", ans);
    return 0;
}

/*
*/
原文地址:https://www.cnblogs.com/CJLHY/p/9130288.html