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 ...
随机推荐
- Ubuntu 16.04 安装ROS sudo rosdep init报错问题
解决博文:https://blog.csdn.net/weixin_37835458/article/details/79878785 输入sudo rosdep init报错如下: Tracebac ...
- float元素上-margin的用法
css标准,float元素上的负margin表示把下面的元素向对应方向移动,并且覆盖上一个元素(这里是指html中元素的声明顺序). 标准情况下我们用float 时候是这样的. -margin通俗点说 ...
- paramiko linux pip18.1
Collecting paramiko Downloading https://files.pythonhosted.org/packages/cf/ae/94e70d49044ccc234bfdba ...
- Python - 代码片段,Snippets,Gist
说明 代码片段来自网上搬运的或者自己写的 华氏温度转摄氏温度 f = float(input('请输入华氏温度: ')) c = (f - 32) / 1.8 print('%.1f华氏度 = %.1 ...
- 多数据库:SQLHelper
//=============================================================================== // This file is ba ...
- Assign the task-HDU3974 dfs序+线段树
题意: 一个公司有n个员工,每个员工都有一个上司,一个人下属的下属也是这个人的下属,因此可将他们的关系看成一棵树, 然后给定两种操作,C操作是查询当前员工的工作,T操作是将y工作分配给x员工,当一个人 ...
- Primecoin在windows上的部署和启动服务
Primecoin在windows上的部署和启动服务: 一.从官方获得Primecoin的windows版安装包: 二.一路像安装客户端一样的安装: 三.安装成功后它会自动弹出客户端运行,同步数据, ...
- macOS 10.14+ 安装LTP
LTP是哈尔滨工业大学(HIT,窝工)出品的一个自然语言处理工具包.其功能包括中文分词(“分词效果好于jieba分词”[引用自学长]).词性标注.实体识别等. 对于macOS来说,现有的版本可能不多, ...
- RESTful风格化
RESTful Web Service介绍 Roy Thomas Fielding博士2000年提出的 REST是英文Representational State Transfer的缩写 表象化状态转 ...
- json 常用的方法
JSON 是用于存储和传输数据的格式. JSON 通常用于服务端向网页传递数据 . ------- 菜鸟网 1. JSON.parse() :用于将一个 JSON 字符串转换为 JavaScrip ...