//伪概率DP
#include<bits/stdc++.h>
using namespace std;
int hm, high, low, n, m, c, a, b, t;
int delta;
double dp[810][16001], sum[16001];
inline int read(){
int num = 0;
char c;
while((c = getchar()) == ' ' || c == '\r' || c == '\n');
num = c - '0';
while(isdigit(c = getchar())) num = num*10 + c - '0';
return num;
}
inline void getInit(){
memset(dp, 0, sizeof(dp));
}
int main(){
t = read();
while(t--){
m = read(); c = read();
n = read(); a = read();
b = read();
getInit();
delta = b - a + 1;
hm = m + c;
low = n * a;
high = n * b;
if(high < m){
printf("0.00000\n");
continue;
}
else if(low > hm){
printf("0.00000\n");
continue;
}
for(int i = a; i <= b; i++) dp[1][i] = 1;
for(int i = 1; i <= n; i++){
dp[i][a*i] = 1;
dp[i][b*i] = 1;
}
for(int i = 2; i <= n; i++){
memset(sum, 0, sizeof(sum));
for(int j = i*a-b; j <= i*b-a; j++) sum[j] = sum[j-1] + dp[i-1][j];
for(int j = i*a+1; j <= i*b-1; j++)
//for(int k = a; k <= b; k++)
//if(j - k >= 0)
dp[i][j] += sum[j-a] - sum[j-b-1]; //dp[i-1][j-k];
}
double ans = 0;
long long final = 1;
for(int i = 1; i <= n; i++) final *= (long long)delta;
for(int i = m; i <= hm; i++) ans += dp[n][i];
ans /= (double)final;
printf("%.5lf\n", ans);
}
return 0;
}
暑末 Day1 Face
最新推荐文章于 2022-09-29 23:06:59 发布