Cain trapped in a maze, the maze has n exits, Cain can randomly choose a daily exit, each exit has some monsters, Cain need c[i] Force value to spend t[i] days passed. Otherwise Cain cannot pass, and he
The force value will increase c[i].
Give the c[i of N Road], T[i] and Cain The initial force value, to find the desired number of days to leave the maze.
By the topic can be found, should seize the change of force value.
Dp[i]: Force value in the case of I go out of the desired number of days. Cain may choose to go out of the way, may also choose to go out of the way.
Dp[i] = (Σt[j] +σ (1 + dp[i+c[k]))/n; (C[j] < I, c[k] >= i)
Because the road does not go out of the value of force will grow c[i], so there is no way out of the situation.
Tips: Using recursive notation is easier and easier to understand.
/*********************************************** * * Problem ID:zoj_3640.cpp * * Create Time:thu Jul 20:57:26 * A Uther Name:xuelanghu * * Auther blog:blog.csdn.net/xuelanghu407 **********************************************/# Include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm >using namespace Std;int N, f;int c[110];int t (int c) {return (int) (1 + sqrt (5))/2 * c * c);} Double DP (int f) {Double res = 0.0;for (int i=0; i<n; i++) {if (F > C[i]) {res + = t (C[i]);} else {res + = (1 + DP (f + c[i]));}} return res/n;} int main () {while (CIN >> n >> F) {for (int i=0; i<n; i++) {cin >> c[i];} printf ("%.3lf\n", DP (f));} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Zoj 3640 probability DP