\(\color{#0066ff}{ 题目描述 }\)

lxhgww的小名叫”小L“,这是因为他总是很喜欢L型的东西。小L家的客厅是一个R*C的矩形,现在他想用L型的地板来铺满整个客厅,客厅里有些位置有柱子,不能铺地板。现在小L想知道,用L型的地板铺满整个客厅有多少种不同的方案?需要注意的是,如下图所示,L型地板的两端长度可以任意变化,但不能长度为0。

铺设完成后,客厅里面所有没有柱子的地方都必须铺上地板,但同一个地方不能被铺多次。

\(\color{#0066ff}{输入格式}\)

输入的第一行包含两个整数,R和C,表示客厅的大小。接着是R行,每行C个字符。'_'表示对应的位置是空的,必须铺地板;'*'表示对应的位置有柱子,不能铺地板。

\(\color{#0066ff}{输出格式}\)

输出包含q行,第i行为m[i]个整数,该行的第j(j=1,2...,,m[i])个数表示第i年被授权的聚居地h[j]的临时议事处管理的种族个数。

\(\color{#0066ff}{输入样例}\)

3 3
___
_*_
___

\(\color{#0066ff}{输出样例}\)

8

\(\color{#0066ff}{数据范围与提示}\)

测试点编号      数据范围
1,2 R*C<=25
3-5 R*C<=100并且(R=2或者C=2)
6-10 R*C<=100

\(\color{#0066ff}{ 题解 }\)

一道不错的插头DP

情况要考虑全面

考虑插头,0:无,1:未拐弯插头,2:已拐弯插头(题中要求必须是拐弯的砖)

套板子就行啦

再次声明,我TM就不写hash表,暴力卡常开\(O2\),980ms卡过去!!!

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
std::unordered_map<int, int> f[2];
int n, m, s, t;
bool mp[120][120];
char getch() {
char ch = getchar();
while(ch != '*' && ch != '_') ch = getchar();
return ch;
}
void init() {
n = in(), m = in();
static bool cp[120][120];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cp[i][j] = getch() == '_';
if(m > n) {
std::swap(n, m);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) {
mp[i][j] = cp[j][i];
if(mp[i][j]) s = i, t = j;
}
}
else {
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) {
mp[i][j] = cp[i][j];
if(mp[i][j]) s = i, t = j;
}
}
}
const int mod = 20110520;
int pos(int v, int x) { return (v << (x << 1LL)); }
void ins(int &x, int y) { x %= mod, (x += y) %= mod; }
int work() {
int now = 0, nxt = 1;
int ans = 0;
f[now][0] = 1;
int U = (1 << ((m + 1) << 1)) - 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
f[nxt].clear();
for(auto &k:f[now]) {
int S = k.first, val = k.second;
int L = (S >> ((j - 1) << 1)) & 3, R = (S >> (j << 1)) & 3;
if(!mp[i][j]) {
if(!L && !R) ins(f[nxt][S], val);
continue;
}
if(!L && !R) {
//right 1
if(mp[i][j + 1]) ins(f[nxt][S ^ pos(1, j)], val);
//down 1
if(mp[i + 1][j]) ins(f[nxt][S ^ pos(1, j - 1)], val);
//middle double 2
if(mp[i][j + 1] && mp[i + 1][j]) ins(f[nxt][S ^ pos(2, j - 1) ^ pos(2, j)], val);
}
//要么直走还是1,要么拐弯变成2
else if(L == 0 && R == 1) {
if(mp[i + 1][j]) ins(f[nxt][S ^ pos(1, j - 1) ^ pos(1, j)], val);
if(mp[i][j + 1]) ins(f[nxt][S ^ pos(1, j) ^ pos(2, j)], val);
}
//要么直走还是2,要么停下变成0
else if(L == 0 && R == 2) {
if(mp[i + 1][j]) ins(f[nxt][S ^ pos(2, j - 1) ^ pos(2, j)], val);
ins(f[nxt][S ^ pos(2, j)], val);
}
//跟上面差不多
else if(L == 1 && R == 0) {
if(mp[i][j + 1]) ins(f[nxt][S ^ pos(1, j - 1) ^ pos(1, j)], val);
if(mp[i + 1][j]) ins(f[nxt][S ^ pos(1, j - 1) ^ pos(2, j - 1)], val);
}
else if(L == 2 && R == 0) {
if(mp[i][j + 1]) ins(f[nxt][S ^ pos(2, j - 1) ^ pos(2, j)], val);
ins(f[nxt][S ^ pos(2, j - 1)], val);
}
//必须拼上,没有其他情况
else if(L == 1 && R == 1) {
ins(f[nxt][S ^ pos(1, j - 1) ^ pos(1, j)], val);
}
//这些情况都是不成立的
else if(L == 1 && R == 2) {}
else if(L == 2 && R == 1) {}
else if(L == 2 && R == 2) {}
if(i == s && j == t) {
//1 1 // 0 2 // 2 0 第一个是接上,后两个是直接停下,都可以收集ans
if(L + R == 2) ins(ans, val);
}
}
std::swap(now, nxt);
}
f[nxt].clear();
for(auto &k:f[now]) ins(f[nxt][(k.first << 2) & U], k.second);
std::swap(nxt, now);
}
return ans;
}
int main() {
init();
printf("%d\n", work() % mod);
return 0;
}

P3272 [SCOI2011]地板的更多相关文章

  1. P3272 [SCOI2011]地板(插头DP)

    [题面链接] https://www.luogu.org/problemnew/show/P3272 [题目描述] 有一个矩阵,有些点必须放,有些点不能放,用一些L型的图形放满,求方案数 [题解] ( ...

  2. 洛谷P3272 [SCOI2011]地板(插头dp)

    传送门 感谢大佬的教导->这里 容易注意到,本题的合法路径“L型地板”有一些特殊的地方:拐弯且仅拐弯一次. 这由于一条路径只有两种状态:拐弯过和没拐弯过,因此我们可以尝试着这样定义新的插头: 我 ...

  3. bzoj 2331: [SCOI2011]地板 插头DP

    2331: [SCOI2011]地板 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 541  Solved: 239[Submit][Status] D ...

  4. 【BZOJ2331】[SCOI2011]地板 插头DP

    [BZOJ2331][SCOI2011]地板 Description lxhgww的小名叫“小L”,这是因为他总是很喜欢L型的东西.小L家的客厅是一个的矩形,现在他想用L型的地板来铺满整个客厅,客厅里 ...

  5. bzoj:2331: [SCOI2011]地板

    Description lxhgww的小名叫“小L”,这是因为他总是很喜欢L型的东西.小L家的客厅是一个的矩形,现在他想用L型的地板来铺满整个客厅,客厅里有些位置有柱子,不能铺地板.现在小L想知道,用 ...

  6. 2331: [SCOI2011]地板 插头DP

    国际惯例的题面:十分显然的插头DP.由于R*C<=100,所以min(R,C)<=10,然后就可以愉悦地状压啦.我们用三进制状压,0表示没有插头,1表示有一个必须延伸至少一格且拐弯的插头, ...

  7. BZOJ2331:[SCOI2011]地板——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=2331 题面复制于洛谷 题目描述 lxhgww的小名叫”小L“,这是因为他总是很喜欢L型的东西.小L家 ...

  8. 【BZOJ】2331: [SCOI2011]地板 插头DP

    [题意]给定n*m的地板,有一些障碍格,要求用L型的方块不重不漏填满的方案数.L型方块是从一个方格向任意两个相邻方向延伸的方块,不能不延伸.n*m<=100. [算法]插头DP [题解]状态0表 ...

  9. bzoj2331 [SCOI2011]地板

    Description lxhgww的小名叫“小L”,这是因为他总是很喜欢L型的东西.小L家的客厅是一个的矩形,现在他想用L型的地板来铺满整个客厅,客厅里有些位置有柱子,不能铺地板.现在小L想知道,用 ...

随机推荐

  1. git学习 删除远程分支

    2种方法删除远端分支: git branch -r -d origin/branch-name    // -r:  远端:    -d:删除 git push origin :branch-name ...

  2. Spring学习十一

    一:  创建bean的方法: 1: 如果不采用构造注入:默认调用bean的无参构造函数,因此该类必须要提供无参构造函数,用无参构造函数用反射创建bean. :               如果采用构造 ...

  3. springmvc----demo1---hello---bai

    import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import ...

  4. 关于RandomizedSearchCV 和GridSearchCV(区别:参数个数的选择方式)

    # -*- coding: utf-8 -*- """ Created on Tue Aug 09 22:38:37 2016 @author: Administrato ...

  5. 部署和调优 1.7 samba 部署和优化-1

    Samba服务可以实现linux上共享一个目录,windows上面访问. 安装 yum install -y samba samba-client 配置文件在 vim /etc/samba/smb.c ...

  6. MySQL中的多表插入更新与MS-SQL的对比

    MySQL多表插入: INSERT INTO tdb_goods_cates (cate_name) SELECT goods_cate FROM tdb_goods GROUP BY goods_c ...

  7. buntu下shell脚本运行异常:bash和…

    转载于:http://www.51testing.com/?uid-225738-action-viewspace-itemid-208702 我用bash到语法写了一个shell脚本(准确的说是把书 ...

  8. nodejs的POST请求

    http://blog.csdn.net/puncha/article/details/9015317 Nodejs 发送HTTP POST请求实例 2013-06-03 17:55 71745人阅读 ...

  9. day69-oracle 22-DBCA

    只涉及到数据库的管理,不涉及到数据库的开发.不涉及到写SQL程序或者是写增删改查,不涉及到这些东西,也不涉及到事务. 你在安装oracle的时候它自动帮你创建一个数据库.

  10. 389. Find the Difference 找出两个字符串中多余的一个字符

    [抄题]: Given two strings s and t which consist of only lowercase letters. String t is generated by ra ...