zoukankan      html  css  js  c++  java
  • CF906C Party (状压DP)(未完成//鬼知道啥情况)

    CF上下了数据,本地能过,一交就错
    这状压不用解释,看代码就懂。

    #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;
     
    const int N = 23;
     
    int f[1 << N];
    int a[1 << N];
    int q[N + 7];
    int fa[1 << N];
     
    int main(){
    //FileOpen();
     
    	int n, m;
    	io >> n >> m;
    	
    	if(n == 1 || (n * (n - 1) >> 1) <= m){
    		printf("0");
    		return 0;
    	}
    	
    	int M = (1 << n) - 1;
    	R(i,0,M) f[i] = 0x3f3f3f3f; // can't memset f[] 0x7fffffff directly
    	
    	R(i,1,m){
    		int u, v;
    		io >> u >> v;
    		a[u] |= (1 << (v - 1));
    		a[v] |= (1 << (u - 1));
    	}
    	R(i,1,n){
    		a[i] |= (1 << (i - 1));
    		f[a[i]] = 1;
    		q[a[i]] = i;
    	}
    	R(s,0,M){
    		if(f[s] == 0x3f3f3f3f) continue;
    		R(i,1,n){
    			if(((s >> (i - 1)) & 1) && (f[s | a[i]] > (f[s] + 1))){
    				f[s | a[i]] = f[s] + 1;
    				q[s | a[i]] = i;
    				fa[s | a[i]] = s;
    				
    			}
    		}
    	}
    	
    	printf("%d
    ", f[M]);
    	for(register int i = M; i; i = fa[i]){
    		printf("%d ", q[i]);
    	}
    	return 0;
    }
    
    

  • 相关阅读:
    python 输出所有列表元素的乘积
    shell 变量赋值运算
    shell 判断变量是否为空
    js 获取地址栏域名以及URL
    python 获取列表大于指定长度的元素
    python 判断列表字符串元素首尾字符是否相同
    python 通过列表元素值截取列表并获取长度
    python 判断两个列表是否有公共元素
    python 获取列表的键值对
    python 判断列表的包含关系
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11247072.html
Copyright © 2011-2022 走看看