F - Xor-Path

思路:

双向搜索dfs

如果普通的搜索复杂度是n

那么双向搜索复杂度是√n

代码:

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = ;
LL a[N][N], k, ans = ;
int n, m;
map<LL, LL>mp[N][N];
void dfs_pre(int x, int y, LL sum) {
if(x + y == (n+m+)/) {
mp[x][y][sum]++;
return ;
}
if(x < n) dfs_pre(x+, y, sum^a[x+][y]);
if(y < m) dfs_pre(x, y+, sum^a[x][y+]);
}
void dfs_suf(int x, int y, LL sum) {
if(x + y == (n+m+)/) {
ans += mp[x][y][sum^a[x][y]^k];
return ;
}
if(x > ) dfs_suf(x-, y, sum^a[x-][y]);
if(y > ) dfs_suf(x, y-, sum^a[x][y-]);
}
int main() {
scanf("%d %d %lld", &n, &m, &k);
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++)
scanf("%lld", &a[i][j]);
}
dfs_pre(, , a[][]);
dfs_suf(n, m, a[n][m]);
printf("%lld\n", ans);
return ;
}

Codeforces 1006 F - Xor-Paths的更多相关文章

  1. codeforces 1006 F(折半搜索)

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

  2. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

  3. [codeforces 293]B. Distinct Paths

    [codeforces 293]B. Distinct Paths 试题描述 You have a rectangular n × m-cell board. Some cells are alrea ...

  4. Codeforces 835 F. Roads in the Kingdom

    \(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...

  5. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  6. codeforce F - Three Paths on a Tree

    F. Three Paths on a Tree time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces 1005 F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路: bfs+dfs 首先,bfs找出1到其他点的最短路径大小dis[i] 然后对于2...n中的每个节点u,找到它所能改变的所 ...

  8. Codeforces 617 E. XOR and Favorite Number

    题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...

  9. Codeforces 627 A. XOR Equation (数学)

    题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s    a xor b = x   a, b > ...

随机推荐

  1. fjwc2019 D2T3 排序(堆)

    #183. 「2019冬令营提高组」排序 贴一段ppt 考虑模拟出这个算法进行k轮(即外层的i循环到k)时的序列,之后再暴力模拟零散的步. 考虑这个算法在01序列上的表现,k轮后实际上就是将最开始的不 ...

  2. Apache正向代理和反向代理

    一.正向代理 先说一正向代理(Forward Proxy),通常普通用户使用的比较多的,是正向代理.也就是在浏览器的网络连接属性框中,填写上一个代理服务器的ip和端口,即可通过代理服务器中转,去浏览网 ...

  3. linux远程方式,以及基础命令

    最近准备学习linux系统,购买了阿里巴巴的云服务器,系统为CentOS. 一.连接实例 1.使用管理终端. 这是阿里巴巴云服务器管理控制台,需要登录阿里巴巴,找到自己实例后,点击右侧远程连接即刻. ...

  4. FireMonkey 源码学习(3)

    五.TTextLayoutNG 在FMX.TextLayout.GPU.pas文件中,实现了几个基础功能,其中: (1)渲染单元 在TextLayout中,每一批同字体和颜色的1~n个字符,组成一个最 ...

  5. Android 源码编译 指定userdata.img、system.img、cache.img容量大小【转】

    本文转载自:https://blog.csdn.net/baodinglaolang/article/details/49791041 修改build/target/board/generic_x86 ...

  6. Windows 安装Java与配置环境变量

    window系统安装java 下载JDK 首先我们需要下载java开发工具包JDK,下载地址:http://www.oracle.com/technetwork/java/javase/downloa ...

  7. P4097 [HEOI2013]Segment(李超树)

    链接 https://www.luogu.org/problemnew/show/P4097 https://www.lydsy.com/JudgeOnline/problem.php?id=3165 ...

  8. Unity3D学习笔记(三十二):Xlua(2)

    Xlua支持通过子类对象访问父类的变量属性和方法   对于C#的ref,out参数的方法 当调用的时候:out类型的参数是不需要传递实参的,普通的参数和ref参数需要传递实参. out,ref传出值通 ...

  9. JOISC 2014 邮戳拉力赛(基础DP)

    题意 https://loj.ac/problem/2878 思路 真的神仙题,想到就很好写,想不到就写不出来. 肯定只能一个一个邮戳按顺序分析.首先,将取一枚邮戳的路径分为四种: 上行 \(\rig ...

  10. HDU 4325 Flowers(树状数组+离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...