"Expect DP" ZOJ 3640 help Me Escape

Source: Internet
Author: User

Channel

Test instructions: Vampires in a cave everywhere, he has the initial combat effectiveness, if the combat effectiveness is greater than the C value of the cave he can take time to escape, or his fighting force increased c, and then randomly choose the next cave to go, ask him to spend time to go out of the expectation

Idea: Set Dp[v], which represents the expectation when the capability value is v. So the equation is easy to write, dp[v] = sum{ti/n} (v to escape) + Sum {(1 + dp[v + c[i])/n} (next escape); For road I, if V is greater than the limit of road I, then you can use Ti to escape, the probability of {1/n} otherwise can only enter the next Days of the attempt, so need time for Dp[v + c[i]] + 1, the probability is {1/n};

Code:

#include <iostream>#include<cstdio>#include<string.h>#include<math.h>using namespacestd;#defineN 20005Doubledp[n],t;intc[ the],n,f;DoubleDfsintv) {    inti,j; if(dp[v]>0)returnDp[v];  for(i=0; i<n;i++)    {       if(v>C[i]) {Dp[v]=dp[v]+int(T*c[i]*c[i]) *1.0/N; }       Else{Dp[v]=dp[v]+ (1+dfs (V+c[i])) *1.0/N; }    }    returndp[v];}intMain () {inti,j; T=(1.0+SQRT (5.0))/2.0;  while(~SCANF ("%d%d",&n,&f)) {memset (DP,0,sizeof(DP));  for(i=0; i<n;i++) scanf ("%d",&B[i]); printf ("%.3lf\n", DFS (f)); }    return 0;}
View Code

"Expect DP" ZOJ 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.