山东第四届省赛 I (基础类)
来源:互联网 发布:搜索引擎数据库设计 编辑:程序博客网 时间:2024/04/30 08:26
Description
Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two rooms,the third layer have three rooms …). Now she stands at the top point(the first layer), and the KEY of this maze is in the lowest layer’s leftmost room. Known that each room can only access to its left room and lower left and lower right rooms .If a room doesn’t have its left room, the probability of going to the lower left room and lower right room are a and b (a + b = 1 ). If a room only has it’s left room, the probability of going to the room is 1. If a room has its lower left, lower right rooms and its left room, the probability of going to each room are c, d, e (c + d + e = 1). Now , Mary wants to know how many steps she needs to reach the KEY. Dear friend, can you tell Mary the expected number of steps required to reach the KEY?
Input
Output
Please calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.
Sample Input
30.3 0.70.1 0.3 0.60
Sample Output
3.41
本题的题意十分明显,状态转移也已经明确给出,作为初识概率dp把。有一点要注意概率转移步长加1
#include <map>#include <set>#include <list>#include <deque>#include <queue>#include <stack>#include <cmath>#include <vector>#include <string>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;typedef unsigned long long ULL;#define INF (1<<30)#define prln(x) printf("%lld...\n",x)#define pr(x) printf("%lld...",x)#define EPS 1e-10#define rep(i,n) for(int (i)=(0);(i)<(n);(i)++)#define Rep(i,n) for(int (i)=(1);(i)<=(n);(i)++)const int maxn = 50;double dp[maxn][maxn];double a,b,c,d,e;int n;int main(){ while(scanf("%d",&n)==1 && n){ scanf("%lf %lf %lf %lf %lf",&a,&b,&c,&d,&e); for(int i=n;i>=1;i--) for(int j=1;j<=i;j++){ if(i == n) dp[i][j] = (j-1); else { if(j == 1) dp[i][j] = a*(dp[i+1][j]+1)+b*(dp[i+1][j+1]+1); else dp[i][j] = c*(dp[i+1][j]+1)+d*(dp[i+1][j+1]+1)+e*(dp[i][j-1]+1); } } printf("%.2lf\n",dp[1][1]); } return 0;}
- 山东第四届省赛 I (基础类)
- I。quadratic equation 山东第八届省赛
- 瑞神要考研(山东科技大学第四届ACM校赛)
- 13山东ACM省赛(第四届)problem A Rescue The Princess
- 山东第四届acm省赛总结:
- Java核心技术I——基础点拾掇(第四章)
- 山东农业大学/基础练习题1
- 范睢曰臣居山东(战国策)
- 山东煎饼(贪心)
- 第四届山东ACM省赛---Contest Print Server
- 2011年山东ACM第二届省赛 Mathman Bank(模拟)
- 2014年山东ACM第五届省赛 angry_birds_again_and_again(数学积分)
- 师创杯”山东理工大学第九届ACM程序设计竞赛(网络同步赛)--I皮卡丘的梦想2
- 《算法》第四版第一章以及java核心技术卷I基础部分知识点
- 第四届图灵赛-I、一道不简单的题目(水,读行)
- Java核心技术(卷I)读书笔记 第四~六章
- 第三届山东ACM省赛 Fruit Ninja I
- sdut2415 Chess (山东第三届省赛)
- SQLServer 数据加密解密:将 TDE 保护的数据库移到其他实例(二)
- wireshark中tcpdump过滤方法详解
- Lua_table中常用的四种遍历方式
- 2-3
- sx:tree 标签生成树状的文件列表
- 山东第四届省赛 I (基础类)
- 4.7-ANDROID面试
- CUDA Toolkit v7.0最新技术文档合集
- iOS企业账号发布流程
- Windows上SSH服务器的配置以及客户端的连接
- C++对象向基本类型转换
- Jpexs分析
- NSRunLoop和nstimer
- java基础(一)