问题 F: Flipping Coins
时间限制: 1 Sec 内存限制: 128 MB Special Judge
提交: 129 解决: 58
[提交] [状态] [讨论版] [命题人:admin]
题目描述
Here’s a jolly and simple game: line up a row of N identical coins, all with the heads facing down onto the table and the tails upwards, and for exactly K times take one of the coins, toss it into the air, and replace it as it lands either heads-up or heads-down. You may keep all of the coins that are face-up by the end.
Being, as we established last year, a ruthless capitalist, you have resolved to play optimally to win as many coins as you can. Across all possible combinations of strategies and results, what is the maximum expected (mean average) amount you can win by playing optimally?
输入
•One line containing two space-separated integers:
–N (1 ≤ N ≤ 400), the number of coins at your mercy;
–K (1 ≤ K ≤ 400), the number of flips you must perform.
输出
Output the expected number of heads you could have at the end, as a real number. The output must be accurate to an absolute or relative error of at most 10−6.
样例输入
12 1
样例输出
10.5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <bits/stdc++.h> #define LL long long using namespace std; const int maxn = 410; double dp[maxn][maxn]; int main(){ int n, k; while(~scanf("%d%d", &n, &k)){ memset(dp, 0, sizeof(dp)); double ans = 0; dp[0][0] = 1; for(int i=0; i<k; i++){ for(int j=0; j<n; j++){ dp[i+1][j] += dp[i][j]/2; dp[i+1][j+1] += dp[i][j]/2; } dp[i+1][n] += dp[i][n]/2; dp[i+1][n-1] += dp[i][n]/2; } for(int i=1; i<=n; i++) ans += i*dp[k][i]; printf("%.10lfn", ans); } }
最后
以上就是发嗲奇异果最近收集整理的关于UKIEPC2017 . Flipping Coins(动态规划)的全部内容,更多相关UKIEPC2017内容请搜索靠谱客的其他文章。
发表评论 取消回复