Codeforces Round #199 (Div. 2) D. Xenia and Dominoes
把 '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的更多相关文章
- 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 ...
- Codeforces Round #199 (Div. 2) E. Xenia and Tree
题目链接 2了,差点就A了...这题真心不难,开始想的就是暴力spfa就可以,直接来了一次询问,就来一次的那种,TLE了,想了想,存到栈里会更快,交又TLE了..无奈C又被cha了,我忙着看C去了.. ...
- 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 ...
- 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...
- Codeforces Round #199 (Div. 2)
A.Xenia and Divisors 题意:给定N个数,每个数的取值范围为1-7,N是3的倍数,判定是否能够恰好将N个数分成若干三元组,使得一个组中的元素a,b,c满足 a < b < ...
- 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 ...
- 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 ...
- Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)
题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...
- Codeforces Round #515 (Div. 3)
Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...
随机推荐
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 线性代数
import numpy.matlib import numpy as np a = np.array([[1,2],[3,4]]) b = np.array([[11,12],[13,14]]) p ...
- 重新梳理IT知识之java-02语法(二)
1.如何获取一个随机数 比如:10-99 调用方法:Math.random //Math.random方法得到的是double类型的值范围在[0.0,1.0),一般需要加工后才可满足开发要求. 代码: ...
- ResultSet指针回到初始位置的方法及ResultSet介绍
原文地址: https://blog.csdn.net/walkerjong/article/details/7023872 仅供学习参考使用. 结果集(ResultSet)是数据中查询结果返回的一种 ...
- C++判断txt文件编码格式
转载:https://blog.csdn.net/kikityan/article/details/89923808 记事本打开txt文件,然后另存,有四种编码格式可供选择,分别是:ANSI ...
- ES建立索引步骤, 1,index 2.mapping 3,别名
1.建立索引PUT /index_trans_detail 2.建立mappingPOST /index_trans_detail/type_trans_detail/_mapping{ " ...
- php 高级 提高PHP代码的性能10条建议
1.echo比print要快很多.两个方法都会在页面上打印东西,不过echo不返回任何值,print会在成功或失败的时候返回0或1. 2.include_once比include更加耗时.因为它需要去 ...
- HTML5中改变了哪些东西?
HTML5 推出的理由 想要把目前web上存在的各种问题一并解决 Web浏览器之间的兼容性很低 文档结构不够明确 Web应用程序的功能受到了限制 HTML5重新定义了浏览器的统一标准 HTML5 与 ...
- SQL SERVER2005自动备份 2012.3.29
要想在 SQL2005上进行数据库的自动备份必须把sql server的SQL Server Agent服务开启,否则是无法进行自动备份的 启动完成之后,用户可以直接在“管理”下面的“维护计划”选项来 ...
- 笔记-python-standard library-8.3.collections
笔记-python-standard library-8.3.collections 1. collections简介 Source code: Lib/collections/__init ...
- Cookie信息保存到本地(MozillaCookieJar)
from urllib import request from http.cookiejar import MozillaCookieJar cookiejar = MozillaCookieJar( ...