zoukankan      html  css  js  c++  java
  • 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;
    }
    
    /*
    */
  • 相关阅读:
    poj2481 线段树(单点更新)
    二叉查找树 hdu(3791 && 3999)
    计算机科学32个最重要的算法
    03最小路径覆盖问题
    02太空飞行计划问题
    hdu 2448最短路+最佳匹配
    poj1419 最大团
    hdu 3585(二分+最大团)
    hdu 3622 2-SAT
    hdu3592差分约束
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9130288.html
Copyright © 2011-2022 走看看