HDU 5245 期望概率
2017-11-17 20:34
316 查看
Joyful
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1610 Accepted Submission(s): 707
Problem Description
Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an M×N matrix.
The wall has M×N squares
in all. In the whole problem we denotes (x,y) to
be the square at the x-th
row, y-th
column. Once Sakura has determined two squares (x1,y1) and (x2,y2),
she can use the magical tool to paint all the squares in the sub-matrix which has the given two squares as corners.
However, Sakura is a very naughty girl, so she just randomly uses the tool for K times.
More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all the M×N squares,
with equal probability. Now, kAc wants to know the expected number of squares that will be painted eventually.
Input
The first line contains an integer T(T≤100),
denoting the number of test cases.
For each test case, there is only one line, with three integers M,N and K.
It is guaranteed that 1≤M,N≤500, 1≤K≤20.
Output
For each test case, output ''Case #t:'' to represent the t-th
case, and then output the expected number of squares that will be painted. Round to integers.
Sample Input
2
3 3 1
4 4 2
Sample Output
Case #1: 4
Case #2: 8
题意:一个大矩形由M*N个小方块组成,一个人每次选两个小方块,他可以对以这两个方块为顶点的矩形面积内的小方块上色,他一共可选k次,现在求被上色的小方块数目的期望
每个块可以重复选择,每个点可以重复染色,染几次就算几次。第一个方块的选择有n*m种,第二个方块有n*m种选择,所以共有n*m*n*m种选择。
定义运算p(a,b)=a*b*a*b;
若对于一个方块a[i,j]不被选择的情况共有p(i-1,N)+p(M-i,N)+p(j-1,M)+p(N-j,M)-p(i-1,j-1)-p(M-i,j-1)-p(N-j,i-1)-p(N-j,M-i)种情况,所以可以算出对于一次选择他不被染色的概率,进而求出K次选择他不被染色的概率。对每个方块进行这样的操作,即可算出期望。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll p(ll a,ll b)
{
return a*a*b*b;
}
int main()
{
int T;
scanf("%d",&T);
int cas=1;
while(T--)
{
ll M,N,K;
scanf("%lld%lld%lld",&M,&N,&K);
ll ans,sum;
double q=0;
double res=0;
sum=p(M,N);
for(ll i=1;i<=M;i++)
{
for(ll j=1;j<=N;j++)
{
ans=0;
ans+=p(i-1,N);
ans+=p(M-i,N);
ans+=p(j-1,M);
ans+=p(N-j,M);
ans-=p(i-1,j-1);
ans-=p(M-i,j-1);
ans-=p(N-j,i-1);
ans-=p(N-j,M-i);
// printf("%lld\n",ans);
q=1.0*ans/sum;
// printf("%lf\n",q);
double tmp=1;
for(ll i=0;i<K;i++)
tmp*=q;
res+=1-tmp;
}
}
printf("Case #%d: %.0lf\n",cas++,res);
}
return 0;
}
相关文章推荐
- HDU 5245 Joyful(概率 期望)
- HDU 5245 上海大都会 J题 (概率期望)
- HDU 5245 Joyful(概率题求期望)
- HDU 5245 Joyful (概率期望)
- HDU 5245 Joyful (数学概率求期望)
- 概率 数学期望 HDU - 5245
- HDU 5245 Joyful (概率题 求期望)
- HDU 5245 Joyful(概率求期望)——2015年上海邀请赛
- HDU 5245 Joyful 【期望概率】
- hdu 4336 Card Collector (概率与期望)
- HDU-4586 Play the Dice(概率期望)
- HDU 3853 LOOPS(概率dp 求期望)
- Hdu 5570 概率期望
- HDU 3853 期望概率DP
- HDU 3853 LOOPS 概率DP 期望
- HDU 5781 ATM Mechine(概率DP求期望)
- [hdu 4405] Aeroplane chess [概率DP & 期望]
- 简单概率dp(期望)-hdu-3853-LOOPS
- HDU 5245 Joyful (2015年上海大都赛J题,概率)
- HDU 4438 Hunters 概率期望 2012 Asia Tianjin Regional Contest