time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a rectangular grid of size n×mn×m. Each cell has a number written on it; the number on the cell (i,ji,j) is ai,jai,j. Your task is to calculate the number of paths from the upper-left cell (1,11,1) to the bottom-right cell (n,mn,m) meeting the following constraints:

  • You can move to the right or to the bottom only. Formally, from the cell (i,ji,j) you may move to the cell (i,j+1i,j+1) or to the cell (i+1,ji+1,j). The target cell can't be outside of the grid.
  • The xor of all the numbers on the path from the cell (1,11,1) to the cell (n,mn,m) must be equal to kk (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).

Find the number of such paths in the given grid.

Input

The first line of the input contains three integers nn, mm and kk (1≤n,m≤201≤n,m≤20, 0≤k≤10180≤k≤1018) — the height and the width of the grid, and the number kk.

The next nn lines contain mm integers each, the jj-th element in the ii-th line is ai,jai,j (0≤ai,j≤10180≤ai,j≤1018).

Output

Print one integer — the number of paths from (1,11,1) to (n,mn,m) with xor sum equal to kk.

Examples
input

Copy
3 3 11
2 1 5
7 10 0
12 6 4
output

Copy
3
input

Copy
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
output

Copy
5
input

Copy
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
output

Copy
0
Note

All the paths from the first example:

  • (1,1)→(2,1)→(3,1)→(3,2)→(3,3)(1,1)→(2,1)→(3,1)→(3,2)→(3,3);
  • (1,1)→(2,1)→(2,2)→(2,3)→(3,3)(1,1)→(2,1)→(2,2)→(2,3)→(3,3);
  • (1,1)→(1,2)→(2,2)→(3,2)→(3,3)(1,1)→(1,2)→(2,2)→(3,2)→(3,3).

All the paths from the second example:

  • (1,1)→(2,1)→(3,1)→(3,2)→(3,3)→(3,4)(1,1)→(2,1)→(3,1)→(3,2)→(3,3)→(3,4);
  • (1,1)→(2,1)→(2,2)→(3,2)→(3,3)→(3,4)(1,1)→(2,1)→(2,2)→(3,2)→(3,3)→(3,4);
  • (1,1)→(2,1)→(2,2)→(2,3)→(2,4)→(3,4)(1,1)→(2,1)→(2,2)→(2,3)→(2,4)→(3,4);
  • (1,1)→(1,2)→(2,2)→(2,3)→(3,3)→(3,4)(1,1)→(1,2)→(2,2)→(2,3)→(3,3)→(3,4);
  • (1,1)→(1,2)→(1,3)→(2,3)→(3,3)→(3,4)(1,1)→(1,2)→(1,3)→(2,3)→(3,3)→(3,4).

题意:从$(1, 1)$走到$(n, m)$,路径上权值异或起来为$k$的有几条

昨晚前五题都1A之后有点上天qwq。。想了很久才发现这是个思博题不过没时间写了qwq。

考虑如果直接dfs的话是$2^{n + m}$

然后meet in the middle 一下就好了

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define MP(x, y) make_pair(x, y)
#define Pair pair<int, int>
#define int long long
using namespace std;
const int MAXN = * 1e5 + , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M, K;
int a[][];
cc_hash_table<int, int> mp[];
int dfs(int x, int y, int now) {
if(x < || x > N || y < || y > M) return ;
if(x + y == (N + M + ) / ) return mp[x][now ^ a[x][y]];
int ans = ;
ans += dfs(x - , y, now ^ a[x - ][y]);
ans += dfs(x, y - , now ^ a[x][y - ]);
return ans;
}
void fuck(int x, int y, int now) {
if(x < || x > N || y < || y > M) return ;
if(x + y == (N + M + ) / ) {mp[x][now]++; return ;}
fuck(x + , y, now ^ a[x + ][y]);
fuck(x, y + , now ^ a[x][y + ]);
}
main() {
#ifdef WIN32
freopen("a.in", "r", stdin);
#endif
N = read(); M = read(); K = read();
for(int i = ; i <= N; i++)
for(int j = ; j <= M; j++)
a[i][j] = read();
fuck(, , a[][]);
printf("%lld", dfs(N, M, K ^ a[N][M]));
}
/*
1 1 1000000000000000000
1000000000000000000
*/

最新文章

  1. 使用Astah制作UML时序图
  2. awk打开多个文件的方法
  3. Android登录界面实现
  4. 微软BI 之SSIS 系列 - 再谈Lookup 缓存
  5. P121 6.7 第一题和第二题
  6. BZOJ2694: Lcm
  7. mysql中删除表
  8. 反射消除String类对象的不可变特性
  9. HTTP协议和web工作原理
  10. vue原来可以这样上手
  11. Tomcat内核之类加载器工厂
  12. 【原】无脑操作:HTML5 + CSS + JavaScript实现比赛排程
  13. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习6
  14. ionic3 热更新发布步骤记录
  15. Uva514
  16. hdoj1232 畅通工程(并查集)
  17. 1010 Radix (25)(25 point(s))
  18. Java的类名与文件名必须一致
  19. centos7 配置php-fpm
  20. python的正则表达一

热门文章

  1. [转]jQuery TextBox Water Mark with asp.net
  2. 怎么为android控件边缘添加阴影
  3. CentOS下NFS服务器配置教程
  4. NLog学习笔记二:深入学习
  5. c#-day01学习笔记
  6. 斗鱼扩展--notifications提示(十二)
  7. 了解委托(Delegate)
  8. jsp---tomcat===》》内置对象
  9. ArrayList、Vector、HashMap、HashSet
  10. Android中关于XML的一个小问题——使用XML输出“&lt;”错误的问题