题目链接:点击打开链接
题解:点击打开链接
爱神写的很详细了嘛⊙﹏⊙
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int kkk[3], a[3];
double p[30];
double dp[551], A[550], B[550];
double work(){
int n; cin>>n;
for(int i = 0; i < 3; i++)cin>>kkk[i];
for(int i = 0; i < 3; i++)cin>>a[i];
double K = 1.0/(kkk[0]*kkk[1]*kkk[2]);
// cout<<"K:"<<K<<endl;
memset(p, 0, sizeof p);
for(int i = 1; i <= kkk[0]; i++)
for(int j = 1; j <= kkk[1]; j++)
for(int k = 1; k <= kkk[2]; k++)
{
if(i==a[0]&&j==a[1]&&a[2]==k)continue;
p[i+j+k] += K;
}
memset(dp, 0, sizeof dp);
memset(A, 0, sizeof A);
memset(B, 0, sizeof B);
for(int i = n; i >= 0; i--)
{
for(int j = 3; j <= kkk[0]+kkk[1]+kkk[2]; j++)
{
A[i] += p[j]*A[i+j];
B[i] += p[j]*B[i+j];
}
B[i] += 1.0;
A[i] += K;
}
dp[0] = B[0] / (1.0 - A[0]);
return dp[0];
}
int main(){
int T; cin>>T;
while(T--)
printf("%.10f\n", work());
return 0;
}