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 ...
随机推荐
- OpenSSL使用指南
OpenSSL使用指南 1 介绍 OpenSSL是使用非常广泛的SSL的开源实现.由于其中实现了为SSL所用的各种加密算法,因此OpenSSL也是被广泛使用的加密函数库. 1.1 SSL ...
- [AngularJS + Webpack] Requiring Templates
With Angular, most of the time you're specifying a templateUrl for your directives and states/routes ...
- systrace跟踪 Android性能优化
http://blog.csdn.net/oujunli/article/details/8138172 http://blog.csdn.net/oujunli/article/details/50 ...
- QT 读写sqllite数据库
QT 读写sqllite数据库 分类: 技术资料2014-04-10 10:39 84人阅读 评论(0) 收藏 举报 #include <QtGui/QApplication> #incl ...
- windows 下解决 Time_Wait 和 CLOSE_WAIT 方法
修改Time_Wait参数的方法 (在服务端修改)Windows下在HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Paramet ...
- mac下的secureCRT破解方案
Mac下面的SecureCRT(附破解方案) 更新到最新的7.3.2 转自 http://bbs.weiphone.com/read-htm-tid-6939481.html 继续更新到7.3.2的破 ...
- HTML简单介绍及常见元素
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 从创建webservice到发布webservice的一些相关总结
最近做了一个web服务,开始什么也不懂,就在网上到处找,对于刚毕业的我,感觉没用实际代码经过自己的手写出来,看什么都一头雾水,然后就看到很多人说webservice已经融入WCF..然后就先创建了WC ...
- TabHost理解与使用
一.继承关系 java.lang.Object ↳ android.view.View ↳ android.view.ViewGroup ↳ android.widget.FrameLayout ↳ ...
- 计算机天才Aaron Swartz 名作 《如何提高效率》——纪念真正的“hacker"!
如何提高效率 <HOWTO: Be more productive>(如何提高效率)作者:Aaron Swartz 肯定有人跟你说过这样的话,“你有看电视的那么长时间,都可以用来写一本书了 ...