zoukankan      html  css  js  c++  java
  • codeforces 167B . Wizards and Huge Prize 概率dp

    题目链接

    dp[i][j][k]表示到第i个人赢了j个人剩余背包容量为k的情况。

    然后转移就可以了。

    #include <iostream>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <bitset>
    using namespace std;
    #define pb(x) push_back(x)
    #define ll long long
    #define mk(x, y) make_pair(x, y)
    #define lson l, m, rt<<1
    #define mem(a) memset(a, 0, sizeof(a))
    #define rson m+1, r, rt<<1|1
    #define mem1(a) memset(a, -1, sizeof(a))
    #define mem2(a) memset(a, 0x3f, sizeof(a))
    #define rep(i, n, a) for(int i = a; i<n; i++)
    #define fi first
    #define se second
    typedef pair<int, int> pll;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int mod = 1e9+7;
    const int inf = 1061109567;
    const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
    double dp[205][205][405], p[205];
    int a[205];
    int main()
    {
        int n, l, tmp;
        cin>>n>>l>>tmp;
        for(int i = 1; i<=n; i++) {
            cin>>p[i];
            p[i]/=100;
        }
        for(int i = 1; i<=n; i++) {
            cin>>a[i];
        }
        dp[0][0][200+tmp] = 1;
        for(int i = 0; i<n; i++) {
            for(int j = 0; j<=i; j++) {
                for(int k = 0; k<=400; k++) {
                    if(a[i+1] == -1) {
                        if(k>0)
                            dp[i+1][j+1][k-1] += dp[i][j][k]*p[i+1];
                        dp[i+1][j][k] += dp[i][j][k]*(1-p[i+1]);
                    } else {
                        int val = min(400, k+a[i+1]);
                        if(k>0)
                            dp[i+1][j+1][val] += dp[i][j][k]*p[i+1];
                        dp[i+1][j][k] += dp[i][j][k]*(1-p[i+1]);
                    }
                }
            }
        }
        double ans = 0;
        for(int i = l; i<=n; i++) {
            for(int j = 200; j<=400; j++) {
                ans += dp[n][i][j];
            }
        }
        printf("%.8f
    ", ans);
        return 0;
    }
  • 相关阅读:
    Valid Parentheses [LeetCode 20]
    线性回归的Spark实现 [Linear Regression / Machine Learning / Spark]
    逻辑回归的分布式实现 [Logistic Regression / Machine Learning / Spark ]
    Python爬虫之豆瓣-新书速递-图书解析
    安装软件包
    打包与压缩
    linux与linux间,互相拷贝文件
    网络管理
    重定向和管道
    索引
  • 原文地址:https://www.cnblogs.com/yohaha/p/5262313.html
Copyright © 2011-2022 走看看