题目链接:Codeforces - Mother of Dragons
显然答案只会在团中产生。到达那个团呢?
假设团的大小为n:k*k/n/n*n*(n-1)/2即为答案。
化简可得:k*k*(1-1/n)/2,可以看出,n越大,答案越大。
所以求最大团即可。
AC代码:
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=45;
int n,k,g[N][N],p[N],cnt,res,s[N];
inline int check(int x){
for(int i=1;i<=cnt;i++) if(!g[s[i]][x]) return 0;
return 1;
}
signed main(){
cin>>n>>k;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>g[i][j];
for(int i=1;i<=n;i++) p[i]=i;
for(int i=1;i<=10000;i++){
random_shuffle(p+1,p+1+n); cnt=0;
for(int i=1;i<=n;i++) if(check(p[i])) s[++cnt]=p[i];
res=max(res,cnt);
}
printf("%.10lf\n",1.0*k*k*(1-1.0/res)/2);
return 0;
}