plw的骰子

版权声明:来自星空计算机团队(QQ群:134826825)——StarSky_STZG https://blog.csdn.net/weixin_43272781/article/details/86555587

http://murphyc.fun/contest/5/problem/G 

Description

duxing2016有一个神奇的骰子,投出1-6的概率为(p1,p2...p6)

现在他投n次骰子,问投出点数和大于等于m的概率是多少

Input

第一行,两个正整数n,m

第二行,六个浮点数 p1,p2,p3,p4,p5,p6

n <= 1000, n <= m <= 6 * n

0<=pi<=1, (p1+p2+p3+p4+p5+p6) = 1

Output

投出点数和大于m的概率p,你的答案与std的误差要<=1e-5

Sample Input 1 

2 7
0 0 0.5 0 0 0.5

Sample Output 1

0.75 

题解:

dp[i][j]为扔完i次骰子后得到的点数和为j的概率,那么很显然转移方程
 

dp[i + 1][j + k] = dp[i][j] * p[k], 1<=k<=6

初始条件也十分的显然,扔0次骰子得到点数和为0概率是1
第一维可以让k从大到小枚举而省去,因为每次肯定是从小的点数转移到大的点数

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
double ans,cnt,flag,temp;
double a[N];
double dp[N][N*6];
char str;
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);
    scanf("%d",&t);
    for(int i=1;i<=6;i++)
        scanf("%lf",&a[i]),dp[1][i]=a[i];
    dp[1][0]=1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=6;j++){
            for(int k=6*(i-1);k>=i-1;k--){
                    dp[i][k+j]=dp[i][k+j]+dp[i-1][k]*a[j];
            }
        }
    }
    ans=0;
    for(int j=6*n;j>=t;j--){
            ans+=dp[n][j];
           // cout<<dp[n][j]<<endl;
    }
    //while(t--){}
    printf("%.6f\n",ans);

    //cout << "Hello world!" << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/86555587