蒟蒻暴力做法求证明复杂度/hack
查看原帖
蒟蒻暴力做法求证明复杂度/hack
196899
lndjy18智99楼主2022/7/1 17:12

思路就是,设 fSf_S 表示集合 SS 里面的点的最大团,转移枚举 lowbit,考虑不选则转移到 S-lowbit,否则,和这个lowbit 有边的点都不能选,转移到 S&e[lowbit]+1。(细节可以看代码)

这个做法看起来状态是 2n2^n 级别,但是过了,求证明复杂度/hack

#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<iomanip>
#define int long long
using namespace std;
int e[55],n;
map<int,int> mp,f;
int dfs(int now)
{
	if(now==0) return 0;
	if(mp.find(now)!=mp.end()) return mp[now];
	int lb=(now&(-now));
	return mp[now]=max(dfs(now-lb),dfs(now&e[f[lb]])+1);
}
signed main()
{
	//freopen("cows.in","r",stdin);
	//freopen("cows.out","w",stdout);
    int k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			int x;
            cin>>x;
            if(x==1)
			e[i]|=1ll<<j;
		}
	}
	for(int i=0;i<n;i++)
	f[1ll<<i]=i;
	double ans=dfs((1ll<<n)-1);
    ans=k*k/ans*(ans-1)/2;
    cout<<fixed<<setprecision(10)<<ans;
 	return 0;
}

2022/7/1 17:12
加载中...