标签:content inline data 正数 产生 attr text bit bsp
1
1 1 1 1
0.25
#include <bits/stdc++.h> using namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } double dp[55][8][8][8]; double dfs(int n,int a,int b,int c) //记忆化搜索 { if(n<=0) return 0; if(dp[n][a][b][c]) return dp[n][a][b][c]; double t=0; int now = a+b+c+1; t+=(double)1/now*(dfs(n-1,a,b,c)+1); //打主人 注意这里要加一个c if(a) { t+=(double)a/now*dfs(n-1,a-1,b,c); } if(b) { if(now-1==7){ t+=(double)b/now*dfs(n-1,a+1,b-1,c); } else{ t+=(double)b/now*dfs(n-1,a+1,b-1,c+1); } } if(c) { if(now-1==7) { t+=(double)c/now*dfs(n-1,a,b+1,c-1); } else { t+=(double)c/now*dfs(n-1,a,b+1,c); } } dp[n][a][b][c] = t; return t; } int main() { int T; T=read(); int n,a,b,c; while(T--) { // memset(dp,0,sizeof(dp)); n=read(); a=read(); b=read(); c=read(); printf("%.2f\n",dfs(n,a,b,c)); } return 0; }
标签:content inline data 正数 产生 attr text bit bsp
原文地址:https://www.cnblogs.com/hao-tian/p/10088922.html