Poj 2096 collecting bugs probability dp (Water

Source: Internet
Author: User

Question link: Click the open link

Question:

Click Open Link

Here the DP practices are:

Write a State X, and then transfer from XGo outX = Y1 + y2 + ···

All Yi values are known.

In this way, we will obtain an equation from unknown to known.

However, DP is from known to unknown. So let's get back ..



# Include <cstdio> # include <iostream> # include <cstring> # include <queue> # include <algorithm> # include <map> # include <cmath> using namespace STD; const int n = 1005; double DP [N] [N]; // DP [I] [J] indicates that I system has been found, and the number of days of J bug int N, s; double solve () {DP [N] [s] = 0.0; For (INT I = N; I> = 0; I --) {for (Int J = s; j> = 0; j --) {if (I = N & J = s) continue; DP [I] [J] = (n-I) * (S-j) * DP [I + 1] [J + 1] + I * (S-j) * DP [I] [J + 1] + (n-I) * j * DP [I + 1] [J] + N * s; DP [I] [J]/= N * s-I * j;} return DP [0] [0];} int main () {While (CIN> N> S) printf ("%. 4f \ n ", solve (); Return 0 ;}


Poj 2096 collecting bugs probability dp (Water

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.