• HDU3915 Game 高斯消元


    题目链接

    HDU3915 Game 高斯消元

    题解

    求异或方程组自由元的子集个数
    高斯消元求秩,内存溢出好神

    代码

    #include<bitset>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std ;
    inline int read() { 
    	int x = 0,f = 1; 
    	char c = getchar(); 
    	while(c < '0' ||c > '9'){if(c == '-') f = -1;c = getchar();}  
    	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
    	return x * f; 
    } 
    bitset<105>a[32]; 
    int n; 
    void gauss(int equ ,int var) { 
    	int r , c , t ; 
    	for(r = c = 1;r <= equ && c <= var;++ r ,++ c) { 
    		t = r; 
    		for(;t < equ;++ t) if(a[t][c]) break ; 
    		if(t == equ) {  
    			-- r ;continue ; 
    		} else swap(a[t] , a[r]);  
    		for(int i = r + 1;i <= equ;++ i) if (a[i][c]) a[i] ^= a[r]; 
    	}
    	int n = var - r , ans = 1; 
    	for(int i = 1;i <= n;++ i) { 
    		ans <<= 1 ;ans %= 1000007; 
    	} 
    	printf("%d
    ",ans); 
    } 
    int main () {
    	int T = read();
    	while(T --) { 
    		for(int i = 1;i <= 31; ++ i) a[i] = 0; 
    		n = read(); 
    		for(int x,i = 1;i <= n;++ i) { 
    			x = read(); 
    			for(int j = 1;j <= 31;++ j) a[j][i] = ((x >> j) & 1);//,printf("%d
    ",n); 
    		} 
    		gauss(31,n); 
    	} 
    	return 0 ;
    } 
    
  • 相关阅读:
    HDOJ 1202 The calculation of GPA
    HDOJ 1197 Specialized Four-Digit Numbers
    HDOJ 1196 Lowest Bit(二进制相关的简单题)
    HDOJ 1194 Beat the Spread!(简单题)
    NOIP2018游记
    CF1043
    洛谷P1280 尼克的任务
    洛谷P1155 双栈排序
    SPOJ6340 ZUMA
    chessboard
  • 原文地址:https://www.cnblogs.com/sssy/p/9332592.html
Copyright © 2020-2023  润新知