[TOJ 3978] Probability II
来源:互联网 发布:手机app设计软件 编辑:程序博客网 时间:2024/05/17 09:13
3978. Probability II
Before read this problem, you should read the problem "Probability I" to get some background information.
In fact, Bob is far more intelligent than we have imagined. He will vindicate to Alice at any point which means he may say to Alice that he love her directly. Bob knows that if he do this at the point i, he can success with the probabilitypi4. But if he fails, he must be back to the point 1. And at the point n he don’t need Vindicate to Alice. Bob is not brave enough as ZHENGWEI, so he decides that he will vindicate at most m times. If he all failed at the m times, he won’t vindicate again which means he will then try his best to show step by step until he reaches the point n. Now we want to know how many expect times Bob have to show using his best strategy.(When Bob directly say to Alice, it is also once show).
Input
There will be several test cases, and each test case input as follows:
The first line input n(1≤n≤1000), m(1≤m≤1000). Then there will be n-1 lines following. Each of the following lines contains four real number pi1, pi2, pi3, pi4. You can trust that pi1+pi2+pi3=1(pi1, pi2 and pi3 have been described in the problem "Probability I". 0 ≤ pi1, pi2, pi3, pi4≤ 1, pi3=0 at point n-1).
Output
For each test case, please output the expect times that Bob has to show to Alice. Answers must be rounded to one digits after the decimal point. If he can’t reach at the point n, please output "impossible".
Sample Input
2 1
0.3 0.7 0.0 1.0
3 1
0.2 0.3 0.5 0.2
0.3 0.7 0.0 1.0
Sample Output
1.0
1.6
dp再加上一些概率上的问题 先推公式,然后每次可以有两种选择, 从后向前递推求解。
#include<iostream>#include<cstring>#include<iomanip>#include<cmath>#include<algorithm>#include<cstdio>using namespace std;int n,m;const double inf=101010101010.0;double dp[1200][1200];double p[1200][4];int main(){ while(cin>>n>>m) { memset(dp,0,sizeof(dp)); bool flag=1; for(int i=1;i<=n-1;i++) cin>>p[i][0]>>p[i][1]>>p[i][2]>>p[i][3]; for(int j=m;j>=0;j--) for(int i=n-1;i>=1;i--) if(j==m) dp[i][j]=(dp[i+1][j]*p[i][1]+dp[i+2][j]*p[i][2]+1)/(1-p[i][0]); else dp[i][j]=min((dp[i+1][j]*p[i][1]+dp[i+2][j]*p[i][2]+1)/(1-p[i][0]),dp[1][j+1]*(1-p[i][3])+1); double ans=inf; for(int i=0;i<=m;i++) ans=min(ans,dp[1][i]); if(ans>101010100) puts("impossible"); else printf("%.1f\n",ans); }}
- [TOJ 3978] Probability II
- TOJ 3977 Probability I
- TOJ Right Triangles II
- Probability
- Probability
- Probability
- Probability
- Probability
- probability
- Probability
- Probability
- TOJ 3667 HDU 2830 Matrix Swapping II
- TOJ 3778.Sheldon's Friendship II
- TOJ 2380 POJ 2536 Gopher II /二分图
- toj 2196 Nuanran's Idol II multiset应用
- Toj 3990. I guess the gift is a bag! II
- [TOJ]1151. Task Sequences [zoj]3332.Strange Country II --竞赛图的哈密顿路
- Probability: Expectation
- JAVA常用类之——正测表达式
- Codeforces Round #256 (Div. 2)
- noHandlerFound问题
- UI开发中的辅助方法
- obj-y, obj-m
- [TOJ 3978] Probability II
- 【Android UI】自定义带按钮的标题栏
- 开发者利器之火狐浏览器Firefox的同步方法
- 在线考试(2)
- 切换kde风格和desktop风格
- scanf格式化输入详解
- 跟我一起写 Makefile(七)
- PCIe SSD 性能调优--PCIe,BIOS配置篇
- 在线考试(3)