lightoj_1030 Discovering Gold

Source: Internet
Author: User

Topic links

Test instructions

In a 1 X N grid, each lattice has a certain amount of gold, you start from the first lattice, ask the last lattice to get the gold expectations.

Each advance using a dice point to determine the number of steps forward, if the point of the cast will be more than N, then re-throw.

Ideas:

A very direct expectation problem.

The probability DP is expected from the forward, the probability of each time is 1/6.

Dp[i] = 1/6 * (dp[i + 1] + Dp[i + 2] + Dp[i + 3] + Dp[i + 4] + Dp[i + 5] + Dp[i + 6]) + x[i].

Depending on the number of points thrown plus whether the current position will exceed N to determine the added item in parentheses, there is a probability.

Code:

  

1#include <cmath>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <ctime>6#include <Set>7#include <map>8#include <list>9#include <queue>Ten#include <string> One#include <vector> A#include <fstream> -#include <iterator> -#include <iostream> the#include <algorithm> - using namespacestd; - #defineLL Long Long - #defineMAXN 110 + #defineMOD 1000000007 - #defineEPS 1e-6 + intN; A DoubleDP[MAXN]; at  - intMain () - { -     intT; -     intKcase =0; -scanf"%d", &T); in      while(T--) -     { toscanf"%d", &n); +          for(inti =1; I <= N; i + +) -scanf"%LF", &dp[i]); the          for(inti = n-1; I >=1; I--) *         { $             if((n-i) >=6)Panax Notoginseng                  for(intj =1; J <=6; J + +) -Dp[i] + = Dp[i + j]/6.0; the             Else  +                  for(intj =1; J <= (N-i); J + +) ADp[i] + = Dp[i + j]/(Double) (N-i); the         } +printf"Case %d:%.7lf\n", + + kcase, dp[1]); -     } $     return 0; $}
View Code

lightoj_1030 Discovering Gold

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.