codeforces D. Painting The Wall
http://codeforces.com/problemset/problem/399/D
题意:给出n和m,表示在一个n*n的平面上有n*n个方格,其中有m块已经涂色。现在随机选中一块进行涂色(如果已经涂色跳过,也消耗时间),消耗1个步骤。终止条件为每行每列都有至少有一块瓷砖被涂色。问说涂成满意的情况需要时间的期望。
思路:把整个方格分成四部分,如果选择左上角上的一块,那么行和列都将被涂上一个;右上角的话,行被涂上一个,列不变;左下角的话,行不变,列被涂上一个;右下角,行列都不变。
状态转移方程:dp[i][j]=(dp[i+1][j]*(n-i)*j+dp[i][j+1]*(n-j)*i+dp[i+1][j+1]*(n-i)*(n-j)+n*n)/(n*n-i*j);
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std; int n,m;
int nr[],nc[];
double dp[][]; int main()
{
scanf("%d%d",&n,&m);
int tr=,tc=;
for(int i=; i<=m; i++)
{
int r,c;
scanf("%d%d",&r,&c);
if(!nr[r])
{
tr++;
nr[r]++;
}
if(!nc[c])
{
tc++;
nc[c]++;
}
}
dp[n][n]=;
for(int i=n; i>=; i--)
{
for(int j=n; j>=; j--)
{
if(i!=n||j!=n)
dp[i][j]=(double)((n-i)*j*dp[i+][j]+i*(n-j)*dp[i][j+]+(n-i)*(n-j)*dp[i+][j+]+n*n)/(n*n-i*j);
}
}
printf("%.10lf\n",dp[tr][tc]);
return ;
}
codeforces D. Painting The Wall的更多相关文章
- 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 ...
- Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP
D. Painting The Wall ...
- 【CF398B】B. Painting The Wall(期望)
B. Painting The Wall time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 507B. Painting Pebbles 解题报告
题目链接:http://codeforces.com/problemset/problem/509/B 题目意思:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色 ...
- codeforces C. Painting Fence
http://codeforces.com/contest/448/problem/C 题意:给你n宽度为1,高度为ai的木板,然后用刷子刷颜色,可以横着刷.刷着刷,问最少刷多少次可以全部刷上颜色. ...
- [Codeforces 448C]Painting Fence
Description Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion ...
- Codeforces 576E Painting Edges [分治,并查集]
洛谷 Codeforces 建议阅读这篇博客作为预备.无耻地打广告 思路 与bzoj4025很相似,思路也差不多,可以看上面那篇博客. 仍然是用二分图的充要条件:没有奇环. 然而这题难在每条边的存在时 ...
- Codeforces 448C Painting Fence(分治法)
题目链接:http://codeforces.com/contest/448/problem/C 题目大意:n个1* a [ i ] 的木板,把他们立起来,变成每个木板宽为1长为 a [ i ] 的栅 ...
- Codeforces 1132C - Painting the Fence - [前缀和优化]
题目链接:https://codeforces.com/contest/1132/problem/C 题意: 栅栏有 $n$ 个节,有 $q$ 个人可以雇佣来涂栅栏,第 $i$ 个人可以涂第 $l_i ...
随机推荐
- 往另外1个ListView中添加当前选中的项目
//往另外1个ListView中添加当前选中的项目 function AddSelItems(listview1:TListView;ListView2:TListView):Boolean; ...
- android异步任务载入数据界面实现
android 异步任务的一个后台方法本质是开启一个线程完毕耗时操作,其它onPostExecute方法和onPreExecute方法执行在UI主线程用于更新UI界面.为了提高用户体验常见的异步任务载 ...
- hdoj Last non-zero Digit in N! 【数论】
找规律! 求N!最后非0位的值.比方2是120的最后一个不是0的值. 输入N比較大,要大数保存. 注意到最后0的个数是与5的因数的个数相等.设f(n)为n!的最后非0位. 那么f(n)=((n%5)! ...
- MySQL 的 read_buffer_size 参数是如何影响写缓冲和写性能的?
Each thread // that does a sequential scan . The value of this variable should be a multiple of 4KB. ...
- A different twist on pre-compiling JSPs--reference
I’ve blogged about this topic earlier and expressed my frustrations as to how web containers don’t p ...
- http学习笔记一
- .NET Core的介绍
ASP.NET5应用程序默认使用.net core来构建应用程序,.net core是一个小的,优化过的.net运行时应用程序. 1. 什么是的.NET Core .NET Core 5 是一由模块化 ...
- MongoDB 重启之后无法连接问题
困扰了一段时间的问题终于知道原因了,每次重启MongoDB服务器就会导致无法启动服务. 通过观察发现,每一次重启完了之后,MongoDB 会进行内存数据加载,而原来服务器内存配置过低,因此导致内存加载 ...
- Asp.net Mvc4 基于Authorize实现的模块访问权限
在MVC中,我们可以通过在action或者controller上设置Authorize[Role="xxx"] 的方式来设置用户对action的访问权限.显然,这样并不能满足我们的 ...
- How to customize authentication to my own set of tables in asp.net web api 2?
ssuming your table is called AppUser, convert your own AppUser domain object to IUser(using Microsof ...