uva 10529 - Dumb Bones(概率dp)
来源:互联网 发布:windows 7模拟器手机版 编辑:程序博客网 时间:2024/06/05 09:02
Problem D: Dumb Bones
You are trying to set up a straight line of dominos, standing on end, to be pushed over later for your entertainment. (Sure, it seems pointless to set something up only to knock it down again, but you have some strange hobbies) The tricky thing about setting dominos, however, is that if you make a mistake and knock one over as you place it, it will knock down any adjacent line of consecutive dominos on one side of it, partially ruining your work.For instance, if you've already placed dominos in the pattern DD__DxDDD_D, and you try placing a domino at position x, there is a chance it will fall and knock over the domino to the left or the three dominos to its right, forcing you to place them again.
This human error is somewhat unavoidable, but you can make the odds somewhat more favourable by using a domino-placing technique that leads to dominos falling in one direction more often than in the other.
Given the number of dominos you are trying to set up, and the probability that you'll knock over any individual domino either to the left or to the right while placing it, determine the average number of dominos you'll need to place before you finish. Assume that you're using an optimal placement strategy.
Input will consist of up to 100 cases. Each case consists of one line of input. It will contain the number of dominos to place, n, 1 <= n <= 1000, followed by nonnegative values Pl and Pr, indicating the probability of any domino falling to the left or to the right when placed. You may assume 0 < Pl + Pr <= 0.5.
The last test case is followed by a line containing a single 0.
For each case, output the expected number of dominos that will need to be placed before you finish, accurate to two digits after the decimal.
Sample Input
10 0.25 0.2510 0.1 0.410 0.0 0.50
Sample Output
46.2537.2820.00
D. Kisman
dp[i]表示构成连续i张牌的期望。枚举构成连续i张牌的最后一张牌的位置,dp[i]取期望最小值。
#include<cstdio>#include<map>#include<queue>#include<cstring>#include<iostream>#include<cstring>#include<algorithm>#include<vector>#include<stack>#include<cmath>using namespace std;const int maxn = 1000 + 5;const int INF = 1000000000;const double eps = 1e-6;typedef long long LL;typedef pair<int, int> P;double dp[maxn];int main(){ int n; double pl, pr; while(cin >> n){ if(n == 0) break; cin >> pl >> pr; dp[1] = 1/(1-pl-pr); dp[0] = 0; for(int i = 2;i <= n;i++){ double Min = (double)INF; for(int j = 0;j < i;j++){ int l = j, r = i-j-1; double x = (1+pl*dp[l]+pr*dp[r])/(1-pl-pr); Min = min(Min, x+dp[l]+dp[r]); } dp[i] = Min; } printf("%.2lf\n", dp[n]); } return 0;}
- uva 10529 - Dumb Bones(概率dp)
- UVA 10529 - Dumb Bones(概率+区间dp)
- uva 10529 - Dumb Bones(概率+区间dp)
- UVa 10529 : Dumb Bones(期望DP)
- UVA 10529 Dumb Bones 概率dp 求期望
- UVa 10529 Dumb Bones 期望DP
- UVa 10529 - Dumb Bones
- UVa10529 Dumb Bones ( 期望概率DP )
- uva 10529 Dumb Bones 区间期望dp ★★
- 【UVA 10529】多米诺骨牌(Dumb Bones)(BSOI4920)
- [UVA]10529 Dumb Bones 期望 + 区间DP DP函数单调性优化
- POJ 2327 Dumb Bones
- uva 19759 (Dp+概率)
- UVA 11021(概率DP)
- UVa 11021 - Tribles (概率DP)
- UVA - 1498 Activation (DP+概率)
- Uva 10081 Tight words (概率DP)
- Uva 11181 Probability|Given(概率dp)
- lihgtoj 1006
- lucene 4.x 近实时搜索
- Oracle中创建视图
- android操作sqlite数据库及心得
- 从Hadoop框架与MapReduce模式中谈海量数据处理(含淘宝技术架构)
- uva 10529 - Dumb Bones(概率dp)
- uva 847 - A Multiplication Game(规律)
- 「我只是认真」聊聊工匠情怀
- Hibernate_10_继承实例_单表
- 高新技术前篇,知识点:枚举类型,反射
- lightoj 1007
- c#多线程 Invoke方法的使用
- 关于浏览器核心的一些思考
- JavaFX文档(9)掌握FXML——1 为何选择FXML