• Luogu3694 邦邦的大合唱站队 (状压DP)


    状态由(从前往后排好的长度)(排好的团队)决定,(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;
    
    int num[21], sum[100007][21];
    int bin[21];
    int f[(1 << 20) + 7];
    
    int main(){
    	int n, m;
    	io >> n >> m;
    	R(i,1,n){
    		int x;
    		io >> x;
    		R(j,1,m) sum[i][j] = sum[i - 1][j];
    		++num[x];
    		++sum[i][x];
    	}
    	
    	bin[1] = 1;
    	R(i,2,m) bin[i] = bin[i - 1] << 1;
    	
    	Fill(f, 0x3f3f3f3f);
    	f[0] = 0;
    	
    	int maxx = (1 << m) - 1;
    	R(i,0,maxx){
    		int len = 0;
    		R(j,1,m){
    			if(i & bin[j]){
    				len += num[j];
    			}
    		}
    		R(j,1,m){
    			if(i & bin[j]){
    				f[i] = Min(f[i], f[i ^ bin[j]] + num[j] - (sum[len][j] - sum[len - num[j]][j]));
    			}
    		}
    	}
    	
    	printf("%d", f[maxx]);
      
    	
    	return 0;	
    }
    

  • 相关阅读:
    ES6rest运算符
    厉害啦,可视化低代码编程平台开源了
    流媒体服务器
    umi的HTML 模板
    reactrouter 中的history
    umi如何在主文件(类似index.html)document.ejs中引入js文件
    开源项目思路
    舌苔黄腻
    [转]IBM GDC,你不会有创新!
    halconrectangle1_domain获取指定矩形区域的图像
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11221869.html
Copyright © 2020-2023  润新知