第四个样例没过,为什么AC了?
  • 板块B3618 寻找团伙
  • 楼主hh_h_hh
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/24 20:27
  • 上次更新2024/10/24 21:10:25
查看原帖
第四个样例没过,为什么AC了?
561562
hh_h_hh楼主2024/10/24 20:27
#include<bits/stdc++.h>
using namespace std;

bool a[15][70];
bool ans[15];
bool s[70];
long long ans1;
long long ansf;
int n,k;
int maxn=1e9;

void dfs(int c)
{
	if(c==n+1)
	{
		for(int j=1;j<=k;j++)
		{
			s[j]=0;
		}
		ans1=0;
		for(int i=1;i<=n;i++)
		{
			if(a[i][maxn]==1&&ans[i]==1)
			{
				s[maxn]=1-s[maxn];
			}
		}
		if(s[maxn]!=1)
		{
			return ;
		}
		s[maxn]=0; 
		for(int i=1;i<=n;i++)
		{
			if(ans[i]==1)
			{
				for(int j=1;j<=k;j++)
				{
					if(a[i][j]==1)
					{
						s[j]=1-s[j];
					}
				}
			}
		} 
//		for(int j=1;j<=k;j++)
//		{
//			cout<<s[j]<<"?";
//		}
//		cout<<endl;
		long long t=1;
		for(int j=k;j>=1;j--)
	    {
		    ans1+=t*s[j];
		    t*=2;
		}
		ansf=max(ans1,ansf);
		return ;
	}
	ans[c]=0;
	dfs(c+1);
	ans[c]=1;
	dfs(c+1);
}

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		int y;
		for(int j=1;j<=x;j++)
		{
			cin>>y;
			a[i][y]=1;
			maxn=min(maxn,y);
		//	cout<<maxn<<endl;
		}
	}
	dfs(1);
	cout<<ansf<<endl;
	return 0;
}
2024/10/24 20:27
加载中...