NOIP 模拟 $79\; \rm f$
题解 \(by\;zj\varphi\)
根据期望的线性性可得,把每个点被删的概率加起来即为答案。
设有 \(c_i\) 个点可以到 \(i\),那么这个点被删的概率就是 \(\frac{i}{c_i}\),因为只有这 \(c_i\) 个点可以控制它(自己本身也算),所以只能从这 \(c_i\) 个点中选一个。
Code
#include<bits/stdc++.h>
#define ri signed
#define pd(i) ++i
#define bq(i) --i
#define func(x) std::function<x>
namespace IO{
char buf[1<<21],*p1=buf,*p2=buf;
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?(-1):*p1++
#define debug1(x) std::cerr << #x"=" << x << ' '
#define debug2(x) std::cerr << #x"=" << x << std::endl
#define Debug(x) assert(x)
struct nanfeng_stream{
template<typename T>inline nanfeng_stream &operator>>(T &x) {
bool f=false;x=0;char ch=gc();
while(!isdigit(ch)) f|=ch=='-',ch=gc();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
return x=f?-x:x,*this;
}
}cin;
}
using IO::cin;
namespace nanfeng{
#define pb emplace_back
#define FI FILE *IN
#define FO FILE *OUT
template<typename T>inline T cmax(T x,T y) {return x>y?x:y;}
template<typename T>inline T cmin(T x,T y) {return x>y?y:x;}
using ll=long long;
static const int N=1e3+7,MOD=998244353;
int n,cnt;
ll ans;
bool vis[N];
std::vector<int> G[N];
char s[N];
auto fpow=[](int x,int y) {
int res=1;
while(y) {
if (y&1) res=1ll*res*x%MOD;
x=1ll*x*x%MOD;
y>>=1;
}
return res;
};
func(void(int)) dfs=[](int x) {
++cnt;
vis[x]=true;
for (auto v:G[x]) if (!vis[v]) dfs(v);
};
inline int main() {
FI=freopen("f.in","r",stdin);
FO=freopen("f.out","w",stdout);
std::cin >> n;
for (ri i(1);i<=n;pd(i)) {
scanf("%s",s+1);
for (ri j(1);j<=n;pd(j)) if (s[j]=='1') G[j].pb(i);
}
for (ri i(1);i<=n;pd(i)) {
cnt=0;
memset(vis+1,false,sizeof(bool)*n);
dfs(i);
ans+=fpow(cnt,MOD-2);
}
printf("%lld\n",ans%MOD);
return 0;
}
}
int main() {return nanfeng::main();}