警钟长鸣,如果你想用数组
查看原帖
警钟长鸣,如果你想用数组
555000
Lucashuang楼主2024/8/24 15:02

千万别用,别问我咋知道的

用了就是TLE

如下图:

奉上TLE代码:

#include<bits/stdc++.h>
using namespace std;
int n , k;
bool vis[30];
int a[30] , a1[100][100];
unsigned long long maxx = 0;
void dfs(int n1){
	int cnt[100] = {};
	unsigned long long sum = 0;
    for(int i = 1; i < n1; i++){
    	for(int j = 1; j <= k; j++){
    		cnt[j] += a1[a[i]][j];
		}
	}
	for(int j = 1; j <= k; j++){
		if(cnt[j] % 2 == 1){
			sum += pow(2 , k - j);
		}
	}
	maxx = max(maxx , sum);
	if(n1 == n + 1){
        return;
    }
    for(int i = a[n1 - 1] + 1; i <= n; i++){
        a[n1] = i;
        dfs(n1 + 1);
    }
}
int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
    	int t;
    	cin >> t;
    	for(int j = 1; j <= t; j++){
    		int t1;
    		cin >> t1;
    		a1[i][t1]++;
		}
	}
	dfs(1);
	cout << maxx;
}
2024/8/24 15:02
加载中...