13年山东省赛——The number of steps
2017-04-13 21:15
387 查看
The number of steps
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Mary standsin 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?
输入
There are nomore than 70 test cases.
In each case , first Input a positive integer n(0
The input is
terminated with 0. This test case is not to be processed.
输出
Please calculatethe expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.
示例输入
3 0.3 0.7 0.1 0.3 0.6 0
示例输出
3.41这里有个链接可以帮助理解:http://kicd.blog.163.com/blog/static/126961911200910168335852/
dp[i][j]从i,j位置到终点的期望步数,所以每算一次要累加,因为是状态转移,注意+1表示多走一步(因为这个怀疑了半天。。。)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
#define PI 3.1415926535897932
#define E 2.718281828459045
#define INF 0x3f3f3f3f
#define mod 100000007
const int M=1005;
int n,m;
int cnt;
int sx,sy,sz;
int mp[1000][1000];
int pa[M*10],rankk[M];
int head[M*6],vis[M*100];
int dis[M*100];
ll prime[M*1000];
bool isprime[M*1000];
int lowcost[M],closet[M];
char st1[5050],st2[5050];
int len[M*6];
typedef pair<int ,int> ac;
//vector<int> g[M*10];
double dp[M][M];
int has[10500];
int month[13]= {0,31,59,90,120,151,181,212,243,273,304,334,0};
int dir[8][2]= {{0,1},{0,-1},{-1,0},{1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
void getpri()
{
ll i;
int j;
cnt=0;
memset(isprime,false,sizeof(isprime));
for(i=2; i<1000000LL; i++)
{
if(!isprime[i])prime[cnt++]=i;
for(j=0; j<cnt&&prime[j]*i<1000000LL; j++)
{
isprime[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
}
struct node
{
int v,w;
node(int vv,int ww)
{
v=vv;
w=ww;
}
};
vector<int> g[M*100];
string str[1000];
int main()
{
int i,j,k,t;
double a,b,c,d,e;
while(~scanf("%d",&n)&&n)
{
scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e);
memset(dp,0,sizeof(dp));
dp
=0;
for(i=n-1;i>=0;i--)dp
[i]+=1.0*(dp
[i+1]+1);//当前位置右边走到终点只能往左走,所以当前的期望=右边+1
for(i=n-1;i>0;i--){
dp[i][i]+=b*(dp[i+1][i]+1)+a*(dp[i+1][i+1]+1);
for(j=i-1;j>0;j--){
dp[i][j]+=d*(dp[i+1][j]+1)+c*(dp[i+1][j+1]+1)+e*(dp[i][j+1]+1);
}
}
/*dp
[1]=0;
for(i=2;i<=n;i++)dp
[i]+=1.0*(dp
[i-1]+1);//当前位置走到终点只能往左走,所以左边一步的期望+1
for(i=n-1;i>0;i--){
dp[i][1]+=a*(dp[i+1][1]+1)+b*(dp[i+1][2]+1);
for(j=2;j<=n;j++){
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;
}
相关文章推荐
- 13年山东省赛 The number of steps(概率dp水题)
- 第四届 山东省ACM The number of steps (概率dp 待整理)
- 山东省第四届ACM大学生程序设计竞赛 The number of steps 概率dp
- 2013山东省第四届ACM省赛 The number of steps
- sdut2623——The number of steps
- UPC2225: The number of steps
- I:The number of steps
- The number of steps
- [2013山东ACM省赛] The number of steps (概率DP,数学期望)
- sdutoj 2623 The number of steps
- upc 2225 The number of steps 期望DP
- sdut 2623 The number of steps (概率dp)
- UPC:2225 The number of steps(概率DP)
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
- SDUT 2623:The number of steps
- The number of steps - UPC 2225 dp
- 第四届 The number of steps
- Codeforces Round #411 (Div. 2) D. Minimum number of steps(思维题目)
- POJ 2699 The Maximum Number of Strong Kings
- [CrackCode] 5.5 Determine the number of bits required to convert integer A to integer B