B. Painting The Wall
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

  1. 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.
  2. User ainta choose any tile on the wall with uniform probability.
  3. If the tile he has chosen is not painted, he paints the tile. Otherwise, he ignores it.
  4. 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.

Input

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 from 1 to n.

Output

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.

Examples
input
5 2
2 3
4 1
output
11.7669491886
input
2 2
1 1
1 2
output
2.0000000000
input
1 1
1 1
output
0.0000000000


 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 2010 double f[Maxn][Maxn];
bool h[Maxn],l[Maxn]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) h[i]=l[i]=;
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
h[x]=;l[y]=;
}
int hh=,ll=;
for(int i=;i<=n;i++) if(h[i]) hh++;
for(int i=;i<=n;i++) if(l[i]) ll++;
for(int i=n;i>=hh;i--)
for(int j=n;j>=ll;j--)
{
if(i==n&&j==n) f[i][j]=;
else
{
double pi=1.0*i/n,pj=1.0*j/n;
f[i][j]=(pi*pj+(f[i+][j]+)*(-pi)*pj+(f[i][j+]+)*pi*(-pj)+(f[i+][j+]+)*(-pi)*(-pj))/(1.0-pi*pj);
}
}
printf("%.10lf\n",f[hh][ll]);
return ;
}

【CF398B】B. Painting The Wall(期望)的更多相关文章

  1. Painting The Wall 期望DP Codeforces 398_B

    B. Painting The Wall time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

                                                                                   D. Painting The Wall ...

  3. CF398B Painting The Wall 概率期望

    题意:有一个 $n * n$ 的网格,其中 $m$ 个格子上涂了色.每次随机选择一个格子涂色,允许重复涂,求让网格每一行每一列都至少有一个格子涂了色的操作次数期望.题解:,,这种一般都要倒推才行.设$ ...

  4. codeforces D. Painting The Wall

    http://codeforces.com/problemset/problem/399/D 题意:给出n和m,表示在一个n*n的平面上有n*n个方格,其中有m块已经涂色.现在随机选中一块进行涂色(如 ...

  5. [Codefoeces398B]Painting The Wall(概率DP)

    题目大意:一个$n\times n$的棋盘,其中有$m$个格子已经被染色,执行一次染色操作(无论选择的格子是否已被染色)消耗一个单位时间,染色时选中每个格子的概率均等,求使每一行.每一列都存在被染色的 ...

  6. cf 398B. Painting The Wall

    23333,还是不会..%%%http://hzwer.com/6276.html #include <bits/stdc++.h> #define LL long long #defin ...

  7. 【HDU4391】【块状链表】Paint The Wall

    Problem Description As a amateur artist, Xenocide loves painting the wall. The wall can be considere ...

  8. HDU 4391 Paint The Wall(分块+延迟标记)

    Paint The Wall Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. 5 Tips for creating good code every day; or how to become a good software developer

    Being a good developer is like being any other good professional, it’s all it’s about doing as much ...

随机推荐

  1. python概念-各类绑定的概念和property的变态一面

    # 编辑者:闫龙 # 1.什么是绑定到对象的方法,如何定义,如何调用,给谁用?有什么特性 #在类中定义的(self)方法都是绑定到对象的方法 #定义 class a: def b(self):#绑定到 ...

  2. 【译】第十二篇 SQL Server代理多服务器管理

    本篇文章是SQL Server代理系列的第十二篇,详细内容请参考原文 在这一系列的上一篇,我们查看了维护计划,一个维护计划可能会创建多个作业,多个计划.你还简单地看了SSIS子系统,并查看了维护计划作 ...

  3. Oracle 11.2.0.4在线(Online mode)打补丁14084247解决WRH$_ACTIVE_SESSION_HISTORY不会自动切割的问题

      安装了Oracle Database Release 11.2.0.4之后,发现WRH$_ACTIVE_SESSION_HISTORY始终不会自动分割删除,   后来才发现需要应用补丁:14084 ...

  4. 我看到的最棒的Twisted入门教程!

    http://www.douban.com/note/232204441/ http://www.cnblogs.com/sevenyuan/archive/2010/11/18/1880681.ht ...

  5. 忘记SVN密码怎么办

    1:下载TSvnPwd.exe 2:使用wireshark抓包.例如: PROPFIND /svn/dev2/!svn/vcc/default HTTP/1.1Host: 192.168.156.1: ...

  6. Shell学习笔记:#*、%*字符串掐头去尾方法

    一.语法 在shell中可以通过#.%对字符串进行掐头去尾操作,使用方法如下: # 表示掐头 % 表示去尾 单个#或%表示最小匹配 双个$或%表示最大匹配  二.例子1 假设我们定义一个变量为: fi ...

  7. 20155225 2016-2017-2 《Java程序设计》第2周学习总结

    20155225 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 比较java和C语言的不同点: java除了基本类型还有类类型 基本类型中还有字节和布尔 对 ...

  8. 20165333 2016-2017-2 《Java程序设计》第1周学习总结

    20165333 2016-2017-2 <Java程序设计>第1周学习总结 教材学习内容总结 java 的地位 Java 的特点 安装JDK 系统环境的设置 Java程序的编写,编译和运 ...

  9. NopCommerce 执行计划任务不同Services协调操作导致更新数据失败的问题!

    问题描述: 在Nop的计划任务里需要两个任务协调操作 _shipmentService.InsertShipment(shipment); _orderProcessingService.Ship(s ...

  10. MIT6.006Lec01:Python实现

    MIT6.006是Algo Intro这门课,据说语言使用python Lec01是讲peak finding,也就是峰值点 具体为: 一维情况下一个数组中a[i]>a[i-1]且a[i]> ...