ZOJ problem Set-3640 help Me Escape

Source: Internet
Author: User
Tags cmath

Main topic:

There are N road, choose the probability of each road is equal, the initial capacity value is f, each road through the difficulty value of CI, when the capacity value is greater than the difficulty of a road a B, can successfully flee, spend time ti, less than equals, can not escape, days plus a day, but the ability to increase the value of B.

Given the initial capability value, the expectation of a successful escape is obtained.

Analysis:

The probability of DP do less, the feeling is not very simple.

Set DP[J] Indicates the expected value of the escape when the capacity is J.

For each road I, when J>c[i], the successful Escape + (ti[i]*p), otherwise plus (+1+dp[j+c[j]]) *p;

From the back forward, to find out dp[f].

Precision Card is very strict, look at the following 2 code on the line

The code of WA

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5#include <iostream>6 #defineINF 100000007 using namespacestd;8 intMain ()9 {Ten     intn,f; One     Doubledp[100000]; A     intc[100000],t[100000]; -      while(SCANF ("%d%d", &n,&f)! =EOF) -     { the         intsum=0, max=-INF; -          for(intI=0; i<n; i++) -         { -scanf"%d",&c[i]); +max=Max (max,c[i]); -             intTt= (int)((1.0+SQRT (5.0))/2.0*c[i]*c[i]); +t[i]=tt; Asum+=T[i]; at         } -         Doublep=1.0/N; -          for(inti=max+1; i<=2*max; i++) -Dp[i]= (Double) sum*p; -          for(intJ=max; j>=f; j--) -         { in             Doubletem=0.0; -              for(intI=0; i<n; i++) to             { +                 if(c[i]<j) -tem+=t[i]*p; the                 Else *tem+= (1+dp[j+c[i]]) *p; $             }Panax Notoginsengdp[j]=tem; -         } theprintf"%.3lf\n", Dp[f]); +     } A     return 0; the}

AC Code

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5#include <iostream>6 #defineINF 100000007 using namespacestd;8 intMain ()9 {Ten     intn,f; One     Doubledp[100000]; A     intc[100000],t[100000]; -      while(SCANF ("%d%d", &n,&f)! =EOF) -     { the         Doublesum=0; -         intmax=-INF; -          for(intI=0; i<n;i++) -         { +scanf"%d",&c[i]); -max=Max (max,c[i]); +             intTt= (int)((1.0+SQRT (5.0))/2.0*c[i]*c[i]); At[i]=tt; atsum+=T[i]; -         } -         Doublep=1.0/N; -          for(inti=max+1; i<=2*max;i++) -dp[i]=sum*p; -          for(intj=max;j>=f;j--) in         { -             Doubletem=0.0; to              for(intI=0; i<n;i++) +             { -                 if(c[i]<j) thetem+=t[i]*p; *                 Else $tem+= (1+dp[j+c[i]]) *p;Panax Notoginseng             } -dp[j]=tem; the         } +printf"%.3lf\n", Dp[f]); A     } the     return 0; +}

ZOJ problem Set-3640 help Me Escape

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.