zoukankan      html  css  js  c++  java
  • Luogu1064 金明的预算方案 (有依赖的背包)

    枚举多个状态

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    //#define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    int w[67][3], val[67][3], items[67];
    int f[32007];
    
    int main(){
    	int V, n;
    	io >> V >> n;
    	R(i,1,n){
    		int v, p, q;
    		io >> v >> p >> q;
    		if(q == 0){
    			w[i][0] = v, val[i][0] = v * p;
    		}
    		else{
    			++items[q];
    			w[q][items[q]] = v;
    			val[q][items[q]] = v * p;
    		}
    	}
    	
    	R(i,1,n){
    		nR(j,V,w[i][0]){
    			if(w[i][0] == 0) continue;
    			f[j] = Max(f[j], f[j - w[i][0]] + val[i][0]);
    			if(items[i] && j >= w[i][1] + w[i][0])
    				f[j] = Max(f[j], f[j - w[i][1] - w[i][0]] + val[i][1] + val[i][0]);
    			if(items[i] == 2 && j >= w[i][2] + w[i][0]){
    				f[j] = Max(f[j], f[j - w[i][2] - w[i][0]] + val[i][2] + val[i][0]);
    			}
    			if(items[i] == 2 &&j >= w[i][2] + w[i][1] + w[i][0]){
    				f[j] = Max(f[j], f[j - w[i][1] - w[i][2] - w[i][0]] +val[i][0] + val[i][1] + val[i][2]);
    			}
    		}
    	} 
    	
    	printf("%d", f[V]);
    	
    	return 0;
    }
    
  • 相关阅读:
    2018.12.29-dtoj-3626
    2018.12.28-bzoj-3784-树上的路径
    2018.12.28-bzoj-2006-[NOI2010]超级钢琴
    2018.12.28-dtoj-3648-寝室管理
    2018.12.27-dtoj-4089-line
    2018.12.27-dtoj-3151-相遇
    2018.12.25-dtoj-4086-针老师(truth) || dtoj-3657: 排列(permutation)
    不要62 hdu2089
    Kia's Calculation hdu4726
    The Moving Points hdu4717
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11361629.html
Copyright © 2011-2022 走看看