标签:from eof not warning data- home form port put
InputThe input contains multiple test cases.
Each test case contains two numbers K and W.
1≤K,W≤20001≤K,W≤2000OutputFor each test case output the answer, rounded to 6 decimal places.Sample Input
1 1 4 2 20 3
Sample Output
1.000000 2.400000 4.523810
求期望逆推,求概率顺推
分情况讨论,如果取钱成功。。如果取钱不成功。。。
注意钱在给定的范围内是等可能分布的
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<sstream> #include<algorithm> #include<queue> #include<vector> #include<cmath> #include<map> #include<stack> #include<set> #include<memory> #include<bitset> #include<string> #include<functional> using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MAXN 2009 #define INF 0x3f3f3f3f /* 概率DP 分为猜中和猜不中两部分计算 dp[i][j] 目前已知金钱范围为0-i 当前还有j次猜的机会 dp[i][j] =min( k从1到i 1 + 取钱成功:(i-k+1)/(i) * dp[i-k][j] + k/(i)*dp[k][j - 1]) dp[1][x] = 1 dp[x][0] = INF */ double dp[MAXN][15]; double E(int v, int k) { if (v == 0) return dp[v][k] = 0; else if (k == 0) return INF; else if (dp[v][k] > 0) return dp[v][k]; else { dp[v][k] = INF; for (int i = 1; i <= v; i++) { dp[v][k] = min(dp[v][k], (double)( v - i +1)/( v + 1) * E(v - i, k) + (double)(i) / ( v + 1) *E(i - 1, k - 1) + 1.0); } return dp[v][k]; } } int main() { int k, w; while (~scanf("%d%d", &k, &w)) { // memset(dp, 0, sizeof(dp)); w = min(w, 15); printf("%.6lf\n", E(k, w)); } }
标签:from eof not warning data- home form port put
原文地址:http://www.cnblogs.com/joeylee97/p/7395509.html