我是靠谱客的博主 发嗲奇异果,这篇文章主要介绍UKIEPC2017 . Flipping Coins(动态规划),现在分享给大家,希望可以做个参考。

问题 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.

 

样例输入

复制代码
1
2 1

 

样例输出

复制代码
1
0.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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部