Lightoj 1030-discovering Gold

Source: Internet
Author: User

The main idea: a person to go to the end of N lattice. Use the dice to determine how many steps you take. Each lattice has gold, asking for the final amount of gold to be expected.

Suppose Dp[i] is the probability to the first lattice.

A[i] for the number of gold in the first lattice.

Then hope is σa[i]*dp[i]

The point is how to find probabilities.

Take a sample example.

3

3 6 9

Dp[1]=1: No problem.

dp[2]=0.5

Dp[3]=dp[1]*0.5+dp[2]*1=1

/************************************************author:guanjuncreated TIME:2016/7/9 23:17:57File name:1 030.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 10010#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespaceStd;priority_queue<int,vector<int>,greater<int> >PQ;structnode{intx, y;};structcmp{BOOL operator() (Node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x; }};BOOLcmpintAintb) {    returnA>b;}intN;DoubleA[MAXN];DoubleDP[MAXN];intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    //freopen ("OUT.txt", "w", stdout);    intT; CIN>>u;  for(intt=1; t<=t;t++) {cin>>N;  for(intI=1; i<=n;i++) scanf ("%LF",&A[i]);        CLE (DP); Doubleans=0; dp[1]=1;  for(intI=1; i<=n;i++){             for(intJ=max (1, I-6); j<i;j++){                intK=min (N-j,6); Dp[i]+=dp[j]/(k*1.0); } ans+=dp[i]*A[i]; } printf ("Case %d:%.10f\n", T,ans); }    return 0;}

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.