调整法+单调性分析(贪心)+折半状压:Cf839E

本文搬运自本人高中时期CSDN博客,若图片加载不出来,可到原文查看:https://blog.csdn.net/zhangtingxiqwq/article/details/135224828

https://vj.imken.moe/contest/599445#problem/D

有以下结论:

  1. 带权子图必为完全图

  2. 内部点权值一定相等

  3. 点个数越多越好

对于1的证明,我们使用调整法。考虑 (x,y)(x,y) 不连通,把 xx 全加到 yy 或把 yy 全加到 xx ,一定有一个更优。

2显然。对于3,设图大小为 tt ,则最终答案为 S22×t1t\frac {S^2} 2\times\frac {t-1}t ,这是一个关于 tt 的函数,且 tt 递增时函数值也递增。

现在求原图最大完全图,直接折半+状压即可。

1
2
3
4
5
pre coding at 14:22
st coding at 14:34
st bugging at 15:50
passing at 16:05
fn blogging at 16:13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stdout, ##__VA_ARGS__)
#else
#define debug(...) void(0)
#endif
//#define int long long
inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'||
ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
#define Z(x) (x)*(x)
#define pb push_back
#define fi first
#define se second
//srand(time(0));
#define N 22
//#define M
//#define mo
int n, m, i, j, k, S, T, b;
int G[N<<1][N<<1], f[1<<N], g[1<<N], s, l, r, t, p;
int h[1<<N], ini;
double ans;

signed main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
// T=read();
// while(T--) {
//
// }
n=read(); S=read(); m=(n+1)/2;
for(i=1; i<=n; ++i) {
for(j=1; j<=n; ++j) G[i][j]=read();
}
for(i=1; i<=n; ++i) for(j=1; j<i; ++j) if(G[i][j]) debug("%d %d\n", i, j);
for(i=1; i<=n; ++i) G[i][i]=1;

l = 1; r = m;
for(s=1; s<(1<<m); ++s) {
for(i=l; i<=r; ++i) if((s>>i-1)&1) g[s]=max(g[s], g[s-(1<<i-1)]);
k = __builtin_popcount(s);
if(k != 1) {
for(i=l; i<=r; ++i) if((s>>i-1)&1) break;
debug("i : %d\n", i);
if(!f[s-(1<<i-1)]) continue;
for(j=l; j<=r; ++j) if( ((s>>j-1)&1) && !G[i][j]) break;
if(j <= r) continue;
}
debug("%d is ok !\n", s);
g[s] = f[s] = k; t = max(t, k);
}
debug("----\n");
l=r+1; r=n; b=l-1;
for(i=l; i<=r; ++i) {
for(j=1; j<=m; ++j) h[i]|=(1<<j-1)*G[i][j];
debug("h[%d] = %d\n", i, h[i]);
}
memset(f, 0, sizeof(f));
ini=(1<<m)-1; m=n-m;
for(s=1; s<(1<<m); ++s) {
k = __builtin_popcount(s);
if(k != 1) {
for(i=l; i<=r; ++i) if((s>>i-b-1)&1) break;
debug("> %d\n", i);
if(!f[s-(1<<i-b-1)]) continue;
for(j=l; j<=r; ++j) if( ((s>>j-b-1)&1) && !G[i][j]) break;
if(j <= r) continue;
}
f[s] = 1;
for(i=l, p=ini; i<=r; ++i) if((s>>i-b-1)&1) p&=h[i];
debug("%d is ok ! p : %d\n", s, p);
t = max(t, g[p]+k);
}
debug("t : %d\n", t); //t=4;
ans = S*S*(t-1); ans /= t*2;
printf("%.7lf", ans) ;
return 0;
}