Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP
User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the rules below.
- Firstly user ainta looks at the wall. If there is at least one painted cell on each row and at least one painted cell on each column, he stops coloring. Otherwise, he goes to step 2.
- User ainta choose any tile on the wall with uniform probability.
- If the tile he has chosen is not painted, he paints the tile. Otherwise, he ignores it.
- Then he takes a rest for one minute even if he doesn't paint the tile. And then ainta goes to step 1.
However ainta is worried if it would take too much time to finish this work. So he wants to calculate the expected time needed to paint the wall by the method above. Help him find the expected time. You can assume that choosing and painting any tile consumes no time at all.
The first line contains two integers n and m (1 ≤ n ≤ 2·103; 0 ≤ m ≤ min(n2, 2·104)) — the size of the wall and the number of painted cells.
Next m lines goes, each contains two integers ri and ci (1 ≤ ri, ci ≤ n) — the position of the painted cell. It is guaranteed that the positions are all distinct. Consider the rows of the table are numbered from 1 to n. Consider the columns of the table are numbered from1 to n.
In a single line print the expected time to paint the wall in minutes. Your answer will be considered correct if it has at most 10 - 4 absolute or relative error.
5 2
2 3
4 1
11.7669491886
2 2
1 1
1 2
2.0000000000
1 1
1 1
0.0000000000 题意:有一个n*n的墙,现在小明来刷墙,如果每一行每一列都至少有一个格子刷过了就停止工作,否则每次随机选一个格子,如果刷过了就不刷如果没刷过就刷,然后休息一分钟,求停止工作时时间的数学期望(开始之前已经有m个格子刷过了)
题解:dp[i][j]表示还有i行j列未刷
初始化: dp[i][0]=((n-i)/n)*dp[i][0]+dp[i-1][0]*i/n+1;
dp[0][j]=((n-j)/n)*dp[0][j]+dp[0][j-1]*j/n+1;
转移: dp[i][j]=dp[i][j]*(n-i)(n-j)/n^2+dp[i-1][j]*(i*(n-j))/n^2+dp[i][j-1]*((n-i)*j)/n^2+dp[i-1][j-1]*(i*j)/n^2+1;
#include<iostream>
#include<cstdio>
using namespace std;
double dp[][];
int n,m,a[],b[];
int main()
{
cin>>n>>m;
int x,y;
int l=n,r=n;
for(int i=; i<m; i++)
{
cin>>x>>y;
if(!a[x]) l--;
if(!b[y]) r--;
a[x]=,b[y]=;
}
for(int i=; i<=n; i++) dp[i][]=dp[i-][]+(double)n/i;
for(int j=; j<=n; j++) dp[][j]=dp[][j-]+(double)n/j;
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{dp[i][j]=(dp[i-][j]*i*(n-j)+n*n+dp[i][j-]*j*(n-i)+dp[i-][j-]*i*j)/(n*n-(n-i)*(n-j));
}
}
printf("%0.10f\n",dp[l][r]);
return ;
}
代码
Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP的更多相关文章
- Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP
D. Bad Luck Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/pr ...
- Codeforces Round #256 (Div. 2) C. Painting Fence 或搜索DP
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
- Codeforces Round #256 (Div. 2) C. Painting Fence (搜索 or DP)
[题目链接]:click here~~ [题目大意]:题意:你面前有宽度为1,高度给定的连续木板,每次能够刷一横排或一竖列,问你至少须要刷几次. Sample Input Input 5 2 2 1 ...
- Codeforces Round #105 (Div. 2) D. Bag of mice 概率dp
题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemo ...
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator 概率DP
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]
D. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp
E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black ...
- Codeforces Round #233 (Div. 2) B. Red and Blue Balls
#include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...
- 贪心 Codeforces Round #173 (Div. 2) B. Painting Eggs
题目传送门 /* 题意:给出一种方案使得abs (A - G) <= 500,否则输出-1 贪心:每次选取使他们相差最小的,然而并没有-1:) */ #include <cstdio> ...
随机推荐
- ubuntu 18.04 安装.net core
要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系那就只好在琢磨了,然后就发现了在github有安装的方法因为是18.04 所以 wget -qO- https://packages.micro ...
- Linux C动态链接库实现一个插件例子
实现一个简单的计算动态链接库:升级动态链接库后,在不重新编译主程序的情况下,直接生效. lib库: #cat math.c #include <stdio.h> int add(int x ...
- jenkins构建项目记录2(tag)
与jenkins构建项目记录1不同的是通过tag拉去对应版本代码 1.先安装创建(git parameter) 2.general设置 name可任意命名,下面源码管理设置时变量会引用到. 3.源码管 ...
- LBE_登录Demo
目录 服务器 最小资产库创建 entity配置 实体的Python实现 创建第一个空间Space 让entity进入空间Space 客户端(unity) 生成客户端SDK 实现Client部分验证 验 ...
- assert.doesNotThrow()
assert.doesNotThrow(block[, error][, message]) 断言 block 函数不会抛出错误.查阅 assert.throws() 了解更多详情. 当调用 asse ...
- Matlab学习笔记(一)
一.MATLAB概述 (一)运行环境 命令行窗口(Command Window) 表 1-1 数据显示格式设置(e_one_1.m) 格式 实例 说明 format short 3.1416 小数点后 ...
- <vue>…… v-if 与 v-show ……//
#v-if 用法: 根据表达式的值的真假条件渲染元素.在切换时元素及它的数据绑定 / 组件被销毁并重建.如果元素是 <template> ,将提出它的内容作为条件块. 当条件变化时该指令触 ...
- 设计方案--移动端延迟300ms的原因以及解决方案
一.前言 移动端浏览器提供一个特殊的功能:双击(double tap)缩放. 二.移动端延迟300ms的原因 为什么要用触摸事件?触摸事件是移动端浏览器特有的html5事件. 因为移动端的clic ...
- vscode调试nodejs
1.安装nodejs 2.安装vscode 3.vscode安装debugger for chrome插件 4.新建nodejs-test文件夹,新建server.js空白文件,添加内容: var h ...
- ZOJ 3905 Cake
Cake Time Limit: 4 Seconds Memory Limit: 65536 KB Alice and Bob like eating cake very much. One ...