# dp 杂练/专练 round2

bzoj1419Redisgood$bzoj 1419 Red is good$
...dp[i][j]rediblackj$额...dp[i][j]表示red剩i张，black剩j张的期望$
×$每次期望×概率转移就行$
0$注意如果期望在0以下就不取了$
$空间不够，所以滚一下$

//Code by liuchenrui
#include<bits/stdc++.h>
#define N 200010
using namespace std;
double dp[2][5005];
char s[100];
int main(){
//freopen("xxx.in","r",stdin);
int r,b;cin>>r>>b;
for(int i=1;i<=r;i++){
dp[i&1][0]=i;
for(int j=1;j<=b;j++){
double p=(double)i/(i+j);
dp[i&1][j]=p*(dp[(i&1)^1][j]+1)+(1-p)*(dp[i&1][j-1]-1);
if(dp[i&1][j]<0)dp[i&1][j]=0;
}
}
sprintf(s+1,"%.10f",dp[r&1][b]);
int t;
for(int i=1;;i++)if(s[i]=='.'){t=i;break;}
s[t+7]='\0';puts(s+1);
}

bzoj 3036

dis[i]i$dis[i]表示i点到达终点的期望距离$
×$期望×概率转移$

//Code by liuchenrui
#include<bits/stdc++.h>
#define N 200010
using namespace std;
inline void splay(int &v){
v=0;char c=0;int p=1;
while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
v*=p;
}
int nxt[N],fir[N],sz,to[N],len[N],q[N],du[N],n,m;
double dis[N],p[N];
nxt[++sz]=fir[x],fir[x]=sz;
to[sz]=y,len[sz]=z;
}
int main(){
freopen("xxx.in","r",stdin);
splay(n),splay(m);
for(int i=1;i<=m;i++){
int x,y,z;
splay(x),splay(y),splay(z);
}
for(int i=1;i<n;i++)if(du[i])p[i]=1./du[i];
for(int u=fir[v];u;u=nxt[u]){
dis[to[u]]+=p[to[u]]*(dis[v]+len[u]);
if(!--du[to[u]])q[++tail]=to[u];
}
}
printf("%.2f",dis[1]);
}

bzoj1426$bzoj 1426$

f[i]i$f[i]表示已经买了i种票，期望再买多少张票可以凑全$
f[i]=f[i](in)+f[i+1](nin)+1$f[i]=f[i]*(\frac{i}{n})+f[i+1]*(\frac{n-i}{n})+1$

f[i]f[i](in)=f[i+1](nin)+1$f[i]-f[i]*(\frac{i}{n})=f[i+1]*(\frac{n-i}{n})+1$
f[i](nin)=f[i+1](nin)+1$f[i]*(\frac{n-i}{n})=f[i+1]*(\frac{n-i}{n})+1$
f[i]=(f[i+1](nin)+1)(nni)$f[i]=(f[i+1]*(\frac{n-i}{n})+1)*(\frac{n}{n-i})$
f[i]=f[i+1]+nni$f[i]=f[i+1]+\frac{n}{n-i}$
g[i]$g[i]表示期望还要花多少钱$
g[i]=(nin)(g[i+1]+f[i+1])+(in)(g[i]+f[i])+1$g[i]=(\frac{n-i}{n})*(g[i+1]+f[i+1])+(\frac{i}{n})*(g[i]+f[i])+1$
?$什么意思呢?$
11$下一次可能买错，相当于这张邮票1元，同时相当于后面涨了1元，其他没变$
g[i]=(nin)(g[i+1]+f[i+1])+(in)g[i]+(in)f[i]+1$g[i]=(\frac{n-i}{n})*(g[i+1]+f[i+1])+(\frac{i}{n})*g[i]+(\frac{i}{n})*f[i]+1$
ning[i]=(nin)(g[i+1]+f[i+1])+(in)f[i]+1$\frac{n-i}{n}g[i]=(\frac{n-i}{n})*(g[i+1]+f[i+1])+(\frac{i}{n})*f[i]+1$
g[i]=g[i+1]+f[i+1]+ni(ni)nf[i]+nni$g[i]=g[i+1]+f[i+1]+\frac{n*i}{(n-i)*n}*f[i]+\frac{n}{n-i}$
ans=g[0]$ans=g[0]$

//Copyright(c)2016 liuchenrui
#include<bits/stdc++.h>
const int N=10010;
using namespace std;
double f[N],g[N];
int main(){
int x;cin>>x;
for(int i=x-1;~i;i--){
f[i]=f[i+1]+(double)x/(x-i);
g[i]=g[i+1]+f[i+1]+(double)x*i/(x*x-i*x)*f[i]+(double)x/(x-i);
}
printf("%.2f",g[0]);
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120