Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

DP

Posted by ACAccepted at 2019-07-31 09:21:53 on Problem 2096
#include <cstdio>
#define p1 (i*j)
#define p2 ((n-i)*j)
#define p3 (i*(m-j))
#define p4 ((n-i)*(m-j))
using namespace std;

template<typename T>
inline T read()
{
	T x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
	return x*f;
}

const int MAXN=1005;
int n,m;
double dp[MAXN][MAXN];

int main()
{
	n=read<int>();m=read<int>();
	dp[n][m]=0;
	for (int i=n;i>=0;i--)
		for (int j=m;j>=0;j--)
		{
			if (i==n&&j==m) continue;
			dp[i][j]=(n*m+p2*dp[i+1][j]+p3*dp[i][j+1]+p4*dp[i+1][j+1])/(n*m-p1);
		}
	printf("%0.4lf\n",dp[0][0]);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator