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

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

  1. #include <bits/stdc++.h>
  2.  
  3. const int MOD = 1e9 + ;
  4. const int N = 1e4 + ;
  5. const int dir[][] = {{, -}, {, }, {, }, {-, }};
  6. int dp[N][ << ], n, sx, sy;
  7. char s[][N];
  8. int mp1[][N], mp[][N];
  9.  
  10. void M(int &a) {
  11. if (a >= MOD) a -= MOD;
  12. if (a < ) a += MOD;
  13. }
  14.  
  15. int get(int x) {
  16. int cnt = ;
  17. while (x) {
  18. cnt++;
  19. x &= (x - );
  20. }
  21. return cnt;
  22. }
  23.  
  24. int DP() {
  25. for (int i = ; i < ; i++)
  26. for (int j = ; j <= n; j++)
  27. dp[j][i] = ;
  28. dp[][] = ;
  29. for (int i = ; i <= n; i++) {
  30. int no = mp[][i] + mp[][i] * + mp[][i] * ;
  31. for (int j = ; j < ; j++) {
  32. if (j & no) continue;
  33. dp[i][j | no] = dp[i - ][ - j];
  34. if (j == || j == ) {
  35. M(dp[i][j | no] += dp[i - ][]);
  36. }
  37. if (j == ) {
  38. M(dp[i][j | no] += dp[i - ][]);
  39. M(dp[i][j | no] += dp[i - ][]);
  40. }
  41. }
  42. }
  43. return dp[n][];
  44. }
  45.  
  46. int main() {
  47. scanf("%d", &n);
  48. for (int i = ; i < ; i++)
  49. scanf("%s", s[i] + );
  50. for (int i = ; i < ; i++)
  51. for (int j = ; j <= n; j++)
  52. if (s[i][j] == 'O')
  53. sx = i, sy = j, mp1[i][j] = ;
  54. else if (s[i][j] == 'X')
  55. mp1[i][j] = ;
  56. std::vector<int> vec;
  57. for (int i = ; i < ; i++) {
  58. bool flag = ;
  59. int x = sx + dir[i][] * , y = sy + dir[i][] * ;
  60. if (x >= && x < && y >= && y <= n) {
  61. for (int j = ; j <= ; j++) {
  62. if (mp1[sx + dir[i][] * j][sy + dir[i][] * j])
  63. flag = ;
  64. }
  65. } else {
  66. flag = ;
  67. }
  68. if (flag)
  69. vec.push_back(i);
  70. }
  71. int S = << vec.size();
  72. int ans = ;
  73. for (int s0 = ; s0 < S; s0++) {
  74. memcpy(mp, mp1, sizeof(mp));
  75. for (int j = ; j < vec.size(); j++) {
  76. int i = vec[j];
  77. if (s0 >> j & ) {
  78. for (int k = ; k <= ; k++) {
  79. int x = sx + dir[i][] * k, y = sy + dir[i][] * k;
  80. mp[x][y] = ;
  81. }
  82. }
  83. }
  84. int f = get(s0) & ? : -;
  85. M(ans += f * DP());
  86. }
  87. printf("%d\n", ans);
  88. return ;
  89. }

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. js中数组的循环与遍历forEach,map

    对于前端的循环遍历我们知道有 针对js数组的forEach().map().filter().reduce()方法 针对js对象的for/in语句(for/in也能遍历数组,但不推荐) 针对jq数组/ ...

  2. 对于java中反编译命令的使用以及Integer包装类的查看

    Integer是基于int的包装类 我们可以用测试代码来看看Integer类是如何实现装箱和拆箱的 public class BoxAndUnbox { /** * @param args */ pu ...

  3. Mac夜神模拟器99%无法正常使用

    PS:部分因更新OS X导致的卡99%可以尝试更新VBOX来解决此问题. 下载VBOX地址:https://www.virtualbox.org/wiki/Downloads         选择对应 ...

  4. MariaDB-Galera部署

    Galera Cluster:集成了Galera插件的MySQL集群,是一种新型的,数据不共享的,高度冗余的高可用方案,目前Galera Cluster有两个版本,分别是Percona Xtradb ...

  5. QRious入门

    qrious是一款基于HTML5 Canvas的纯JS二维码生成插件.通过qrious.js可以快速生成各种二维码,你可以控制二维码的尺寸颜色,还可以将生成的二维码进行Base64编码. qrious ...

  6. 02使用GitHub远程仓库

    一.远程库配置 由于本地的GIT仓库和GitHub仓库之间的传输是通过SSH加密的,所以需要以下配置: 1.创建SSH key 为什么GitHub需要SSHKey:根据key来授权,有哪些key可以往 ...

  7. Mac OS删除文件夹和文件的命令

    https://www.jianshu.com/p/0376bf0514e3 2017.08.18 17:27* 字数 219 阅读 16709评论 0喜欢 0 rmdir删除空目录,不过一旦目录非空 ...

  8. burpsuite使用--暴力破解

    测试靶机:dvwa 浏览器开启代理,使用burpsuite拦截: 并将拦截到的内容发送到intruder进行暴力破解 右边的Add$和Clear$都是选择爆破范围的操作,一个是选择,一个是清除,这里只 ...

  9. Codeforces #617 (Div. 3) C. Yet Another Walking Robot

    There is a robot on a coordinate plane. Initially, the robot is located at the point (0,0)(0,0) . It ...

  10. Python将数据保存为txt文件的方法

    f = open('name.txt',mode='w') #打开文件,若文件不存在系统自动创建. #参数name 文件名,mode 模式. #w 只能操作写入 r 只能读取 a 向文件追加 #w+ ...