CodeForces1006F-Xor-Paths
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).
Codeforces (c) Copyright 2010-2018 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Jul/18/2018 00:56:41UTC+8 (d2).
Desktop version, switch to mobile version.
题解:提议很好理解,寻找从(1,1)到(n,m)异或为K的路径有多少条;因为n,m<=20;暴力搜索即可DFS,可以双向DFS;
AC代码为:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
unordered_map<ll,ll> mp[21];
ll ans, k, a[21][21];
void dfs1(int i, int j, ll v)
{
v ^= a[i][j];
if(i+j == n+1)
{
++mp[i][v];
return ;
}
if(i<n) dfs1(i+1, j,v);
if(j<m) dfs1(i,j+1, v);
}
void dfs2(int i, int j, ll v)
{
if(i+j == n+1)
{
ans += mp[i][v^k];
return ;
}
v ^= a[i][j];
if(i > 1) dfs2(i-1, j, v);
if(j > 1) dfs2(i, j-1, v);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++) cin>>a[i][j];
}
dfs1(1,1,0); dfs2(n, m, 0);
cout<<ans<<endl;
return 0;
}
CodeForces1006F-Xor-Paths的更多相关文章
- Codeforces Round #498 (Div. 3) 简要题解
[比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements [算法] 将序列中的所有 ...
- CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]
D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满 ...
- CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 好像这个题只能Dsu On Tree? 有根树点分治 统计子树过x的 ...
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
题目链接:Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 第一次写\(dsu\ on\ tree\),来记录一下 \(dsu\ o ...
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip
地址:http://codeforces.com/contest/766/problem/E 题目: E. Mahmoud and a xor trip time limit per test 2 s ...
- codeforces766E Mahmoud and a xor trip(按位统计+树形DP)
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- [LeetCode] Binary Tree Paths 二叉树路径
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- [LeetCode] Unique Paths 不同的路径
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
随机推荐
- Linux命令实战(四)
1.Linux上的文件管理类命令都有哪些,其常用的使用方法及相关示例演示. 文件或目录的新建 touch :将每个文件的访问时间和修改时间修改为当前时间.若文件不存在将会创建为空文件,除非使用-c或- ...
- ubuntu开机自启动服务
ubuntu下一个用来管理开机自启动服务的程序,今天在ss vps上安装时老是提示这个错误,百度后,下面的这个方法可行: vi /etc/apt/source.list 输入i,进入Insert模式 ...
- T-SQL Part VII: CROSS JOIN
虽然不能确定是不是只有个SQL Server提供了Cross Join的功能,貌似W3School的SQL教程中是没有的 SQL教程.而Wikipedia中倒是有,也是最新的SQL:2011SQL:2 ...
- window中php的交互模式
1.配置php的环境变量: 测试: cmd >> php --version 2.在cmd下编写测试脚本 1) php -r + php测试代码: 2) php -a + Enter ...
- [深度学习][图像处理][毕设][笔记][安装环境][下载地址]安装VS2013、matconvnet、cuda、cudnn过程中产生的一些记录,2018.5.6号
最近半个多月,被cuda等软件折磨的死去活来,昨天下午,终于安装好了环境,趁着matlab正在,在线下载VOT2016数据集,3点睡眼惺忪被闹醒后,睡不着,爬上来写这份记录. 先记录一下自己电脑的基本 ...
- SVN积极拒绝解决办法
出现以上情况多数为Linux里面的svn自启动没有设置好,一般是自启文件被废弃了,就算在里面添加自启代码也无效,想要兼容旧版本使用这个文件,只需在root管理员模式下输入代码chmod +x /etc ...
- hdu 2063 过山车 (二分图,最大匹配)
过山车Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- django_1:配置文件
工程下: settings.py(建议设置成如下) DATABASES #数据库配置 DEBUG = True ...
- centos安装后第一次重启,许可协议、Kdump
1.许可协议,服务器键盘操作找到许可 确定(遇到过,第一次懵逼了) 2.Kdump是RHEL提供的一个崩溃转储功能,用于在系统发生故障时提供分析数据,它会占用系统内存,一般选择关闭(默认是关闭)(这个 ...
- PostGIS 递归方法
在Oracle数据库中,有可以实现递归的函数 select * from table_name start with [condition1] connect by [condition2] 最近发现 ...