Xdoj 1020 Acmer to brush the problem (basic DP)

Source: Internet
Author: User

Topic Description Brush problem is each acmer way, known to have N on a OJ topic, the first topic small x can do the probability for Pi (0<=pi<=1,1<=i<=n) small x to do at least the probability of the K-Question input the first line input a positive integer t, (t< =20), indicating that there is a T-group test Sample. The second line enters a positive integer n,k, (1<=n,k<=1000) the third line inputs n decimals, respectively, Pi (1<=i<=n,0<=pi<=1), indicating the probability that small x does the first topic. Output small x do at least the probability of a K-question, and wrap (keep 4 decimal) sample input
21 10.53 20.3) 0.2 0.1
Sample output
0.50000.0980
Tips

Main topic:

This is to give you a probability of doing the right thing for each question, and then, let you find out at least how much the probability of doing the K-question.

Problem Solving Ideas:

In fact, it is not difficult, as long as the launch to Dp[i][j] play just fine, a start to push for a while, and less a condition (q God to the nest to fill up)

State: Dp[i][j] represents the probability of having an I-question, which is a problem for J-questions.

Initial state: Dp[0][0] = 1,dp[0][1] = 0;

State transition equation: dp[i][j] = dp[i-1][j-1]*p[i]+dp[i-1][j]* (1-p[i]);

Dp[i][0] = (1-p[i]) *dp[i-1][0]

Finally only asked to come out sum+=dp[n][k]+dp[n][k+1]+dp[n][k+2]+...+dp[n][n];

Code:

1# include<cstdio>2# include<iostream>3  4 using namespacestd;5  6# define MAX12347  8 DoubleP[max];9 DoubleDp[max][max];Ten intn,k; One   A intMainvoid) - { -     intT;SCANF ("%d",&t); the      while(t-- ) -     { -scanf"%d%d",&n,&k); -          for(inti =1; I <= n;i++ ) +         { -scanf"%LF",&p[i]); +         } Adp[0][0] =1; atdp[0][1] =0; -          for(inti =1; I <= n;i++ ) -         { -dp[i][0] = (1-p[i]) *dp[i-1][0]; -         } -          for(inti =1; I <= n;i++ ) in         { -              for(intj =1; J <= n;j++ ) to             { +DP[I][J] = (1-p[i]) *dp[i-1][j]+p[i]*dp[i-1][j-1]; -             } the         } *         Doublesum =0; $          for(inti = K;i <= n;i++ )Panax Notoginseng         { -sum+=Dp[n][i]; the         } +printf"%.4lf\n", sum); A   the     } +   -   $     return 0; $}

Xdoj 1020 Acmer to brush the problem (basic 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.