zoukankan      html  css  js  c++  java
  • CF580D Kefa and Dishes (状压DP)

    枚举最后食物

    #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;
    #define int long long
    int a[19], val[19][19], f[(1 << 18) + 7][19];
    #undef int
    int main(){
    #define int long long
    	int n, m, k;
        io >> n >> m >> k;
        R(i,1,n)
            io >> a[i];
            
        R(i,1,k){
        	int x, y;
        	io >> x >> y;
        	io >> val[x][y];
        }
        R(i,1,n)
            f[1 << (i - 1)][i]=a[i];
    
    	int ans = 0;
        R(s,0,(1 << n) - 1){
            int tot=0;
            R(i,1,n)
    			if(s & (1 << (i - 1))){
    	            ++tot;
    	            R(j,1,n)
    					if(!(s & (1 << (j - 1)))){
    						f[s | (1 << (j - 1))][j] = Max(f[s | (1 << (j - 1))][j] , f[s][i] + a[j] + val[i][j]);
    					}
    	        }
    	        if(tot == m)
    	        	R(i,1,n)
    					if(s & (1 << (i - 1)))
    	            		ans = Max(ans , f[s][i]);
        }
        
        printf("%lld", ans);
    
        return 0;
    }
    

  • 相关阅读:
    webservice
    AppDomain (转)
    Apache和Nginx防盗链的几种配置方法
    优化PHP代码的40条建议
    file_get_contents无法请求https连接的解决方法
    PHP SPL
    Ubuntu 查看系统信息
    PHP导出Excel
    mysql集群
    配置yum源的两种方法
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11247260.html
Copyright © 2011-2022 走看看