F. Xor-Paths
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)
/*
暴搜2^(n+m)
折半搜索
*/
#include<bits/stdc++.h> #define N 27
#define ll long long using namespace std;
ll n,m,k,ans,flag;
ll a[N][N];
map<ll,ll>M[N][N]; inline ll read()
{
ll x=,f=;char c=getchar();
while(c>''||c<''){if(x=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} void dfs(int dep,int x,int y,ll sta)
{
if(x< || x>n || y< || y>m) return;
if(!flag) sta^=a[x][y];
if(x+y==dep)
{
if(!flag){M[x][y][sta]++;return;}
else{ans+=M[x][y][k^sta];return;}
}
if(!flag){
dfs(dep,x+,y,sta);dfs(dep,x,y+,sta);
}
else{
sta^=a[x][y];
dfs(dep,x-,y,sta);dfs(dep,x,y-,sta);
}
} int main()
{
n=read();m=read();k=read();
for(int i=;i<=n;i++) for(int j=;j<=m;j++)
a[i][j]=read();
flag=;dfs((n+m+)/,,,);
flag=;dfs((n+m+)/,n,m,);
printf("%lld\n",ans);
return ;
}

codeforces 1006 F(折半搜索)的更多相关文章

  1. Codeforces 1006 F - Xor-Paths

    F - Xor-Path 思路: 双向搜索dfs 如果普通的搜索复杂度是n 那么双向搜索复杂度是√n 代码: #include<bits/stdc++.h> using namespace ...

  2. Codeforces#498F. Xor-Paths(折半搜索)

    time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. 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  ...

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

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

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

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

  6. 【BZOJ4800】[CEOI2015 Day2]世界冰球锦标赛 (折半搜索)

    [CEOI2015 Day2]世界冰球锦标赛 题目描述 译自 CEOI2015 Day2 T1「Ice Hockey World Championship」 今年的世界冰球锦标赛在捷克举行.\(Bob ...

  7. 【BZOJ 2679】[Usaco2012 Open]Balanced Cow Subsets(折半搜索+双指针)

    [Usaco2012 Open]Balanced Cow Subsets 题目描述 给出\(N(1≤N≤20)\)个数\(M(i) (1 <= M(i) <= 100,000,000)\) ...

  8. 折半搜索+状态压缩【P3067】 [USACO12OPEN]平衡的奶牛群Balanced Cow S…

    Description 给n个数,从中任意选出一些数,使这些数能分成和相等的两组. 求有多少种选数的方案. Input 第\(1\)行:一个整数\(N\) 第\(2\)到\(N+1\)行,包含一个整数 ...

  9. 【Luogu】P2962灯Lights(折半搜索)

    题目链接 本意是想学高斯消元,然后一顿乱搞之后学到了一个神奇的搜索方式叫做折半搜索. qwq 就是我先dfs前二分之n个点,然后再dfs后二分之n个点. 然后我dfs后二分之n个点的时候判断一下第一次 ...

随机推荐

  1. oracle dtrace for linux

    https://docs.oracle.com/cd/E37670_01/E37355/html/ol_config_dtrace.html#

  2. 【Todo】C++和Java里面的浮点数及各种数字表示

    今天看了这篇文章,是讲C++中的浮点类型的:<浮点数的二进制表示> 再复习一下Java里面的Float和Double. 首先,直接数字赋值给Float变量是不行的,数字后要加上F,这样写: ...

  3. 在SUSE12中使用 Machinery 进行高级系统管理

    简单介绍 在 SUSE Linux Enterprise 12 中.SUSE 如今推出了面向系统管理员的 Machinery.作为其高级系统管理模块的一部分.Machinery 是适用于 Linux ...

  4. 关于rman duplicate 一些比較重要的知识点--系列三

    FYI: http://docs.oracle.com/cd/E11882_01/backup.112/e10643/rcmsynta020.htm#RCMRF126 rman duplicate d ...

  5. Visual Studio VS如何卸载Visual assistant

    1 点击工具-扩展管理器   2 选中Visual Assist X,点击卸载即可.                            

  6. Hive中行列转换

    1.演示多列转为单行 数据文件及内容: student.txt xiaoming|english|92.0 xiaoming|chinese|98.0 xiaoming|math|89.5 huahu ...

  7. Android KK后为何工厂模式下无法adb 无法重新启动机器 ?

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  8. 【转载】在VS2008中使用WSE 3.0过程全记录

    WSE全称是Web Service Enhancement,提供了更好的安全性实现,以及大对象传输的设计. 有关WSE的一些介绍,如果不清楚,可以参考下面的链接 官方介绍:http://www.mic ...

  9. “var arr = []; ”和 “var arr = {};” 的差别

    1.面试题    var arr = [];    var arr = {};    比較上述代码有什么差别? 2.解析    var arr = [];是一个数组对象    var arr = {} ...

  10. ios archives 出现的是other items而不是iOS Apps的解决方案

    ios archives 出现的是other items而不是iOS Apps的解决方案 项目打包时出现的是不是出现在iOS Apps栏目下面,而是Other Items而且右边对应的Upload t ...