标签:print int hide event cli isp click class contest
A.小迟的比赛
最优策略永远是努力应战,dp[i][j]表示前i轮赢了j局的概率,dp[i][j]=dp[i-1][j]*(1-p[i][j])+dp[i-1][j-1]*p[i-1][j-1]
#include <iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; double p[1005][1005]; double dp[1005][1005]; int main() { int n;scanf("%d",&n); for(int i=1;i<=n;i++){ for(int j=0;j<=i-1;j++){ scanf("%lf",&p[i][j]); } } dp[1][1]=p[1][0]; dp[1][0]=1-p[1][0]; for(int i=2;i<=n;i++){ for(int j=0;j<=i;j++){ if(j==0) dp[i][j]=dp[i-1][j]*(1-p[i][j]); else if(j==i) dp[i][j]=dp[i-1][j-1]*p[i][j-1]; else dp[i][j]=dp[i-1][j]*(1-p[i][j])+dp[i-1][j-1]*p[i][j-1]; //printf("%.2f\n",dp[i][j]); } } double ans=0; for(int i=0;i<=n;i++){ ans=ans+i*dp[n][i]; } printf("%.2f\n",ans); return 0; }
标签:print int hide event cli isp click class contest
原文地址:https://www.cnblogs.com/lllxq/p/10270825.html