2 条题解
-
5
给一个刚才写的实现。
考虑倒序执行一个颜色序列,能扩散到 ,则这个颜色序列能作用于 ,当且仅当 。
先求出终点到起点 的最短路,最后作一个高维后缀 即可。
原理参考官解,这里省略。
void P1() { N=(1<<n)-1; rep(t,1,C) { memset(f,0,sizeof(f)); rep(i,1,m) if(c[i]==t) f[u[i]]|=(1<<v[i]),f[v[i]]|=(1<<u[i]); trans[t][0]=0; rep(S,1,N) { trans[t][S]=trans[t][S-(S&(-S))]|f[lg[S&(-S)]]; } rep(S,1,N){ trans[t][S]|=S;} } } void P2() { rep(j,0,N) F[j]={inf,0}; F[1]={0,0}; rep(S,1,N) { if(F[S].first^inf) { rep(c,0,C) { int T=trans[c][S]; F[T]=Min(F[T],make_pair(F[S].first+1,F[S].second+w[c])); } } } } void P3() { int ans1=0,ans2=0; per(S,N,0) { int h=__builtin_popcount(S); ans1+=F[S].first*h; ans2+=F[S].second*h; if(S) rep(i,0,n-1) if(S>>i&1) F[S-(1<<i)]=Min(F[S-(1<<i)],F[S]); } cout<<ans1<<' '<<ans2<<'\n'; }
- 1
信息
- ID
- 49
- 时间
- 3000ms
- 内存
- 500MiB
- 难度
- 8
- 标签
- 递交数
- 38
- 已通过
- 5
- 上传者
