POJ 2096 Collecting Bugs

Source: Internet
Author: User

Title: http://poj.org/problem?id=2096

It is obvious that the state $f (I,J) $ indicates the set of I bugs, the desired number of steps from the set of J system distances.

Then there

$f (I,j), f (i,j) \ P0 = i/n \cdot j/m$

$f (I+1,j), f (i,j) \ P1 = (1-i/n) \cdot j/m$

$f (I+1,j), f (i,j) \ P2 = i/n \cdot (1-j/m) $

$f (I+1,j+1), f (i,j) \ P3 = (1-i/n) \cdot (1-j/m) $

Can be found to be an infinite recursive shape such as:

$f (i,j) = i/n \cdot j/s \cdot (f (i,j) + 1) + S $

$f (i,j) = (ij)/(NM-IJ) + (NS)/(NS-IJ) \cdot S $

Here $s$ represents $p1\cdot F (i+1,j) $ $P 2 \cdot F (i,j+1) $ $P 3 \cdot F (i+1,j+1) $ et cetera

And then you can do it.

#include <cstdio>#include<cstring>#include<algorithm>#defineN 1010#defineLD Doubleusing namespacestd;intn,m; LD F[n][n]; LD S (intIintj) {LD ans=0; if(i<n) ans + = (1.0-i/(LD) n) * j/(LD) m * (1.0+ f[i+1][j]); if(j<m) ans + = i/(LD) n * (1.0-j/(LD) m) * (1.0+ f[i][j+1]); if(i<n&&j<m) ans + = (1.0-i/(LD) n) * (1.0-j/(LD) m) * (1.0+ f[i+1][j+1]); returnans;}intMain () {scanf ("%d%d",&n,&m); F[N][M]=0;  for(inti=n;~i;i--)         for(intj=m;~j;j--){            if(i==n&&j==m)Continue; F[I][J]= i*j/(LD) (N*M-I*J) + (n*m)/(LD) (N*M-I*J) *S (I,J); } printf ("%.4lf\n", f[0][0]); return 0;}
View Code

POJ 2096 Collecting Bugs

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.