HDU 6052 To my boyfriend(概率 贡献)
To my boyfriend
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1246 Accepted Submission(s): 556
I never forget the moment I met with you. You carefully asked me: "I have a very difficult problem. Can you teach me?". I replied with a smile, "of course". You replied:"Given a matrix, I randomly choose a sub-matrix, what is the expectation of the number of **different numbers** it contains?"
Sincerely yours,
Guo
Each case contains two integers, n and m (1≤n, m≤100), the number of rows and the number of columns in the grid, respectively.
The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains g_i,j (0≤ g_i,j < n*m).
2 3
1 2 1
2 1 2
6(size = 1) + 14(size = 2) + 4(size = 3) + 4(size = 4) + 2(size = 6) = 30 / 18 = 6(size = 1) + 7(size = 2) + 2(size = 3) + 2(size = 4) + 1(size = 6)
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 1e2+;;
const int M = ;
const int mod = ;
const int mo=;
const double pi= acos(-1.0);
typedef pair<int,int>pii;
int n,m;
int a[N][N];
int l[N],r[N],pos[N][N*N];
ll ans;
void solve(int x,int y,int col){
int ly=,ry=m+;
for(int i=;i<=n;i++)l[i]=,r[i]=m+;
for(int i=;i<y;i++)l[pos[i][col]]=i;
for(int i=m;i>y;i--)r[pos[i][col]]=i;
for(int i=x;i>pos[y][col];i--){
ly=max(ly,l[i]);
ry=min(ry,r[i]);
ans+=(ll)(n-x+)*(ry-y)*(y-ly);
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
met(pos,);ans=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&a[i][j]);
solve(i,j,a[i][j]);
pos[j][a[i][j]]=i;
}
}
ll all=(ll)n*(n+)*m*(m+)/;
printf("%.9f\n",(double)ans/all);
}
return ;
}
HDU 6052 To my boyfriend(概率 贡献)的更多相关文章
- HDU 6052 - To my boyfriend | 2017 Multi-University Training Contest 2
说实话不是很懂按题解怎么写,思路来源于 http://blog.csdn.net/calabash_boy/article/details/76272704?yyue=a21bo.50862.2018 ...
- HDU 6052 To my boyfriend(悬线法)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6052 [题目大意] 给出一个数字矩阵,求子矩阵期望数字种数 [题解] 我们统计[x,y]为其所表示 ...
- hdu 6052 To my boyfriend
题目 OvO click here http://acm.hdu.edu.cn/showproblem.php?pid=6052 (2017 Multi-University Training Con ...
- 2017ACM暑期多校联合训练 - Team 2 1008 HDU 6052 To my boyfriend (数学 模拟)
题目链接 Problem Description Dear Liao I never forget the moment I met with you. You carefully asked me: ...
- HDU 6052 To my boyfriend(容斥+单调栈)
题意:对于一个n*m的方格,每个格子中都包含一种颜色,求出任意一个矩形包含不同颜色的期望. 思路: 啊啊啊啊啊,补了两天,总算A了这道题了,简直石乐志,前面的容斥还比较好写,后面的那个>13那个 ...
- HDU 3853:LOOPS(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description Akemi Homura is a M ...
- HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2
http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所 ...
- HDU 5781 ATM Mechine (概率DP)
ATM Mechine 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5781 Description Alice is going to take ...
- hdu 4762 Cut the Cake概率公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...
随机推荐
- form:select form:options 标签数据回显
在jsp页面中经常会使用到 form:select form:options 遍历后台List集合生成 select 下拉选择器,但是 form:options 标签并没有提供一个可以回显数据的属性. ...
- conda 虚拟环境
一.jupyter notbook (1)需要安装: conda install ipykernel (2)首先激活对应的conda环境 source activate 环境名称 (3)将环境写入no ...
- HDU 4704 欧拉定理
题目看了很久没看懂 就是给你数n,一种函数S(k),S(k)代表把数n拆成k个数的不同方案数,注意如n=3,S(2)是算2种的,最后让你求S(1~n)的和模1e9+7,n<=1e100000.那 ...
- Python学习笔记(十八)@property
# 请利用@property给一个Screen对象加上width和height属性, # 以及一个只读属性resolution: # -*- coding: utf-8 -*- class Scree ...
- [Luogu 2486] SDOI2011 染色
[Luogu 2486] SDOI2011 染色 树剖水题,线段树维护. 详细题解不写了. 我只想说我写的线段树又变漂亮了qwq #include <algorithm> #include ...
- linux内核文件系统:proc、tmpfs、devfs、sysfs简要介绍
linux内核文件系统:proc.tmpfs.devfs.sysfs proc:虚拟文件系统,在linux系统中被挂载与/proc目录下.里面的文件包含了很多系统信息,比如cpu负载. 内存.网络配置 ...
- Spring Boot工程结构推荐
工程结构(最佳实践) Spring Boot框架本身并没有对工程结构有特别的要求,但是按照最佳实践的工程结构可以帮助我们减少可能会遇见的坑,尤其是Spring包扫描机制的存在,如果您使用最佳实践的工程 ...
- 前端QRCode.js生成二维码(解决长字符串模块和报错问题)
QRCode 用法 1.使用npm安装到你的项目中 npm install qrcode2 --save 使用commonjs或者es6模块方式导入 var QRCode = require('qrc ...
- webgote的例子(4)Sql注入(SelectGET)
SQL Injection (Select/GET) 本章内容 (查询显示中要注意的错误) 这里面我们看一下 movie的数值,选择表单中的当我们选择的二个的时候 move的值也变成了第二个,选择表单 ...
- 保护眼睛(改变窗口颜色和Pdf背景颜色)
保护眼睛(改变窗口颜色和Pdf背景颜色) 昨天用了一个好朋友告诉我的保护眼睛的方法,效果很不错哦-- 今天告诉大家,一起爱护偶们明亮的眼睛吧!!! 首先需要改一下设置,如果常常用电脑很容易 ...