把 'O' 看成 'X',然后枚举它的四个方向看看是否能放,然后枚举 $2^4$ 种可能表示每种方向是否放了,放了的话就标成 'X',就相当于容斥,对于新的图去dp。

dp就是铺地砖,行用二进制来表示是否放了砖块。

#include <bits/stdc++.h>

const int MOD = 1e9 + ;
const int N = 1e4 + ;
const int dir[][] = {{, -}, {, }, {, }, {-, }};
int dp[N][ << ], n, sx, sy;
char s[][N];
int mp1[][N], mp[][N]; void M(int &a) {
if (a >= MOD) a -= MOD;
if (a < ) a += MOD;
} int get(int x) {
int cnt = ;
while (x) {
cnt++;
x &= (x - );
}
return cnt;
} int DP() {
for (int i = ; i < ; i++)
for (int j = ; j <= n; j++)
dp[j][i] = ;
dp[][] = ;
for (int i = ; i <= n; i++) {
int no = mp[][i] + mp[][i] * + mp[][i] * ;
for (int j = ; j < ; j++) {
if (j & no) continue;
dp[i][j | no] = dp[i - ][ - j];
if (j == || j == ) {
M(dp[i][j | no] += dp[i - ][]);
}
if (j == ) {
M(dp[i][j | no] += dp[i - ][]);
M(dp[i][j | no] += dp[i - ][]);
}
}
}
return dp[n][];
} int main() {
scanf("%d", &n);
for (int i = ; i < ; i++)
scanf("%s", s[i] + );
for (int i = ; i < ; i++)
for (int j = ; j <= n; j++)
if (s[i][j] == 'O')
sx = i, sy = j, mp1[i][j] = ;
else if (s[i][j] == 'X')
mp1[i][j] = ;
std::vector<int> vec;
for (int i = ; i < ; i++) {
bool flag = ;
int x = sx + dir[i][] * , y = sy + dir[i][] * ;
if (x >= && x < && y >= && y <= n) {
for (int j = ; j <= ; j++) {
if (mp1[sx + dir[i][] * j][sy + dir[i][] * j])
flag = ;
}
} else {
flag = ;
}
if (flag)
vec.push_back(i);
}
int S = << vec.size();
int ans = ;
for (int s0 = ; s0 < S; s0++) {
memcpy(mp, mp1, sizeof(mp));
for (int j = ; j < vec.size(); j++) {
int i = vec[j];
if (s0 >> j & ) {
for (int k = ; k <= ; k++) {
int x = sx + dir[i][] * k, y = sy + dir[i][] * k;
mp[x][y] = ;
}
}
}
int f = get(s0) & ? : -;
M(ans += f * DP());
}
printf("%d\n", ans);
return ;
}

Codeforces Round #199 (Div. 2) D. Xenia and Dominoes的更多相关文章

  1. Codeforces Round #199 (Div. 2) B. Xenia and Spies

    B. Xenia and Spies time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #199 (Div. 2) E. Xenia and Tree

    题目链接 2了,差点就A了...这题真心不难,开始想的就是暴力spfa就可以,直接来了一次询问,就来一次的那种,TLE了,想了想,存到栈里会更快,交又TLE了..无奈C又被cha了,我忙着看C去了.. ...

  3. Codeforces Round #199 (Div. 2) A Xenia and Divisors

    注意题目的数字最大是7 而能整除的只有 1,2,3,4,6,故构成的组合只能是1,2,4 或1,2,6或1,3,6,故分别统计1,2,3,4,6的个数,然后再分配 #include <iostr ...

  4. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  5. Codeforces Round #199 (Div. 2)

    A.Xenia and Divisors 题意:给定N个数,每个数的取值范围为1-7,N是3的倍数,判定是否能够恰好将N个数分成若干三元组,使得一个组中的元素a,b,c满足 a < b < ...

  6. Codeforces Round #199 (Div. 2) C. Cupboard and Balloons

    C. Cupboard and Balloons time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)

    题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...

  9. Codeforces Round #515 (Div. 3)

    Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...

随机推荐

  1. hexo 搭建静态博客 + Next 主题配置

    参考手册 HEXO:https://hexo.io/zh-cn/ NEXT:http://theme-next.iissnan.com/ 安装hexo npm install hexo-cli -g ...

  2. 【代码审计】VAuditDemo 后台登录功能验证码绕过

    在 admin/logCheck.php中 $_POST['user']和$_POST['pass'] 未经过任何过滤或者编码处理就传入到$query中,可能存在万能密码绕过机制 但是$pass经过了 ...

  3. Ubuntu 16.04 安装ROS sudo rosdep init报错问题

    解决博文:https://blog.csdn.net/weixin_37835458/article/details/79878785 输入sudo rosdep init报错如下: Tracebac ...

  4. IEEE 802.11r-2008

    IEEE 802.11r-2008 or fast BSS transition (FT), also called fast roaming, is an amendment to the IEEE ...

  5. Visual Studio 2017安装MSDN

      在学习Visual Studio 2017的过程中,总会遇到各种各样的难题,这时候你就会求助书或者是网上大佬们的解释,但是在看视频的过程中,我发现了MSDN这个“好东西”,就立马应用于实践,下面把 ...

  6. nodejs下载

    nodejs历史版本 查看npm镜像库 npm config get registry 更改npm镜像库 npm config set registry https://registry.npm.ta ...

  7. RDLC 表达式设置精度

    =IIf(RTrim(Parameters!u_currency.Value)="VND","F0","F2")

  8. python邮箱发送

    普通发送邮件 使用email模块和stmplib模块,内容比较固定,配好了即可实现,代码如下 一.普通邮箱发送 # -*- coding:utf-8-*- import smtplib from em ...

  9. Python中.npz文件的读取

    有时候从网上下载的数据集扩展名(后缀名)是npz,我们需要对数据进行加载(读取):例如:识别猫狗图片的二分类,下的数据集分别为cat.npz和dog.npz import numpy as npcat ...

  10. C++ 知识零碎搭建

    全局变量 局部变量 函数不能嵌套定义 C/C++ 变量在将要被使用时定义即可, 不必一开始就声明所有变量 函数的定义与声明的区别 C++常规类型自动类型转换规则 C语言中十六进制和八进制的格式: 二进 ...