| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
DP#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator