AGC049A Erasing Vertices
WilliamFranklin · · 题解
竟然抢到了一个最优解。
主要思路
考虑把操作次数拆到每一个点上,利用期望的线性性质,分别计算每个点对答案的贡献。
其实可以将一次操作不用真的看作删点,而是每一次选择一个点染成红色,然后把它所能到达的点中尚未染色的点染成蓝色。
记变量
记
对于求
AC Code
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp(Tx, Ty) make_pair(Tx, Ty)
#define For(Ti, Ta, Tb) for(auto Ti = (Ta); Ti <= (Tb); Ti++)
#define Dec(Ti, Ta, Tb) for(auto Ti = (Ta); Ti >= (Tb); Ti--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
const int N = 105;
bitset<N> b[N];
int n;
vector<int> G[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
For(i, 1, n) {
string s;
cin >> s;
b[i][i] = 1;
For(j, 0, n - 1) {
if (s[j] == '1') {
b[i][j + 1] = 1;
}
}
}
For(i, 1, n) {
For(j, 1, n) {
if (b[j][i]) b[j] |= b[i];
}
}
long double ans = 0;
For(i, 1, n) {
long double now = 0;
For(j, 1, n) if (b[j][i]) now++;
ans += 1.0000000000 / now;
}
printf("%.10Lf", ans);
return 0;
}