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
*/

Codeforces#498F. Xor-Paths(折半搜索)的更多相关文章

  1. codeforces 880E. Maximum Subsequence(折半搜索+双指针)

    E. Maximum Subsequence time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces Gym 100231F Solitaire 折半搜索

    Solitaire 题目连接: http://codeforces.com/gym/100231/ Description 给你一个8*8棋盘,里面有4个棋子,每个棋子可以做一下某个操作之一: 1.走 ...

  3. codeforces 1006 F(折半搜索)

    F. Xor-Paths time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索

    Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx  ...

  5. CF 888E Maximum Subsequence——折半搜索

    题目:http://codeforces.com/contest/888/problem/E 一看就是折半搜索?……然后排序双指针. 两个<m的数加起来如果>=m,一定不会更新答案.因为- ...

  6. 【LOJ#6072】苹果树(矩阵树定理,折半搜索,容斥)

    [LOJ#6072]苹果树(矩阵树定理,折半搜索,容斥) 题面 LOJ 题解 emmmm,这题似乎猫讲过一次... 显然先\(meet-in-the-middle\)搜索一下对于每个有用的苹果数量,满 ...

  7. 2018.11.01 NOIP训练 某种密码(折半搜索)

    传送门 直接折半搜索,把所有和装到unorderedmapunordered_mapunorderedm​ap里面最后统计答案就行了. 然后考试的时候读优并没有处理有负数的情况于是爆零了 代码

  8. [折半搜索][哈希]POJ1186方程的解数

    题目传送门 这道题明显N数据范围非常小,但是M很大,所以用折半搜索实现搜索算法的指数级优化,将复杂度优化到O(M^(N/2)). 将搜出的两半结果用哈希的方式合并(乘法原理). Code: #incl ...

  9. 折半搜索【p4799】[CEOI2015 Day2]世界冰球锦标赛

    Description 今年的世界冰球锦标赛在捷克举行.Bobek 已经抵达布拉格,他不是任何团队的粉丝,也没有时间观念.他只是单纯的想去看几场比赛.如果他有足够的钱,他会去看所有的比赛.不幸的是,他 ...

  10. POJ3977:Subset——题解(三分+折半搜索)

    http://poj.org/problem?id=3977 题目大意:有一堆数,取出一些数,记他们和的绝对值为w,取的个数为n,求在w最小的情况下,n最小,并输出w,n. ————————————— ...

随机推荐

  1. OneDrive撸5T硬盘空间教程

    注意:要注册多个账户获取网盘的,用无痕模式打开临时教育邮箱网址.打开之后不要关闭,等会用来接收验证码. 1.需要office 365注册这时候需要教育邮箱: 临时教育邮箱:http://sysu.ed ...

  2. Cloudera Kudu是什么?

    不多说,直接上干货! Cloudera Kudu是什么? kudu是cloudera在2012开始秘密研发的一款介于hdfs和hbase之间的高速分布式列式存储数据库.兼具了hbase的实时性.hdf ...

  3. Andrew Ng 的 Machine Learning 课程学习 (week3) Logistic Regression

    这学期一直在跟进 Coursera上的 Machina Learning 公开课, 老师Andrew Ng是coursera的创始人之一,Machine Learning方面的大牛.这门课程对想要了解 ...

  4. HDU 2255 ——奔小康赚大钱——————【KM算法裸题】

    奔小康赚大钱 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  5. Geek to Live: Set up your personal Wikipedia

    http://lifehacker.com/163707/geek-to-live--set-up-your-personal-wikipedia Filed to: Wikipedia Captur ...

  6. 1.C#中的注释符

    1.软件行业的道德规范 (1).程序员在日常写代码的过程中,一定要养成注释的好习惯,方便后面对理解和使用. (2).在给标识符命名的时候一定要规范,有理有据的,名字不能瞎写. 2.注释 注释符的作用: ...

  7. JavaSE之Java基础(2)

    6.java8新特性 Lambda表达式 接口的默认方法与静态方法 方法引用 重复注解 扩展注解的支持 Optional类 Stream API Date Time API JavaScript引擎N ...

  8. ab (ApacheBench)命令

    ab (ApacheBench)命令 参数 -n 在测试会话中所执行的请求个数.默认时,仅执行一个请求 -c 一次产生的请求个数.默认是一次一个 -t 测试所进行的最大秒数 -k 启用HTTP Kee ...

  9. PHP underlying structure

    http://www.phpinternalsbook.com/classes_objects/magic_interfaces_comparable.html

  10. instanceof和相关函数

    instanceof:如果左边对象是右边类型所表示类(或任意一子类)的一个实例,则返回true,否则false.判断左边真实类型是不是右边的类或它的派生类. //实例一 Object o= new L ...