Zoj 3640 probability DP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.