1. 程式人生 > >bzoj 2784 [JLOI2012]時間流逝——樹上高斯消元

bzoj 2784 [JLOI2012]時間流逝——樹上高斯消元

lan class 就是 com ++ php make pair for

題目:https://www.lydsy.com/JudgeOnline/problem.php?id=2784

一個狀態可以加很多個能量圈,但減少能量圈的情況只有一種。所以可以用樹來刻畫。

然後就變成樹上高斯消元的套路了。註意根節點的 P 等於 0 。

發現不是要求 dp[ 1 ] 就必須在那個式子裏設出 a*dp[ 1 ] 之類的。

據說樹上的點大概有 1.2*106 個。大概就是貝爾數吧。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define mkp make_pair
#define fir first
#define
sec second #define db double using namespace std; const int N=35; int n,m,w[N];db P; pair<db,db> dfs(int lm,int s) { db ta=0,tb=0;if(s>n)return mkp(0,0); for(int i=1;i<=lm;i++) { pair<db,db> v=dfs(i,s+w[i]); ta+=v.fir; tb+=v.sec; } if(!s)P=0; ta=1-(1-P)/lm*ta; ta=1
/ta; tb=((1-P)/lm*tb+1)*ta; ta=P*ta; return mkp(ta,tb); } int main() { while(scanf("%lf",&P)==1) { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++)scanf("%d",&w[i]); sort(w+1,w+m+1);// printf("%.3f\n",dfs(m,0).sec); } return 0; }

bzoj 2784 [JLOI2012]時間流逝——樹上高斯消元