zoukankan      html  css  js  c++  java
  • [luoguP2224] [HNOI2001]产品加工(背包DP)

    传送门

    f[i][j]表示第一个机器耗时j,第二个机器耗时f[i][j]

    第一维可以滚掉

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #define INF 1e9
    #define min(x, y) ((x) < (y) ? (x) : (y))
    #define max(x, y) ((x) > (y) ? (x) : (y))
    
    using namespace std;
    
    int n, m, now = 0, last = 1, ans = 1e9;
    int f[2][30011];
    
    inline int read()
    {
    	int x = 0, f = 1;
    	char ch = getchar();
    	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
    	return x * f;
    }
    
    int main()
    {
    	int i, j, x, y, z;
    	n = read();
    	for(i = 1; i <= n; i++)
    	{
    		x = read(), y = read(), z = read();
    		m += max(x, max(y, z));
    		if(!x) x = INF;
    		if(!y) y = INF;
    		if(!z) z = INF;
    		now ^= 1, last ^= 1;
    		memset(f[now], 127 / 3, sizeof(f[now]));
    		for(j = m; j >= 0; j--)
    		{
    			if(j >= x) f[now][j] = min(f[now][j], f[last][j - x]);
    			f[now][j] = min(f[now][j], f[last][j] + y);
    			if(j >= z) f[now][j] = min(f[now][j], f[last][j - z] + z);
    		}
    	}
    	for(i = m; i >= 0; i--)
    		ans = min(ans, max(i, f[now][i]));
    	printf("%d
    ", ans);
    	return 0;
    }
    

      

  • 相关阅读:
    分离 附加 还原
    sql sever 数据表
    正则矩阵
    路由vue-router基础
    vue理解$nextTick
    vue组件
    vue事件处理
    vue列表渲染
    vue条件渲染
    vue class与style绑定
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/8319799.html
Copyright © 2011-2022 走看看