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. centos 7 安装使用 redis

    1.下载redis,用wget就行,版本在这里找: http://download.redis.io/releases/ 2.安装gcc,tcl,用yum 安装. 3.解压,make ,make in ...

  2. host文件的作用

    什么是host文件 Hosts是一个没有扩展名的系统文件,其基本作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Host ...

  3. webpack --watch和supervisor的不同

     webpack --watch只是热打包,也就是前端代码的热加载,要实现后端代码的热加载,也就是热部署,需要使用supervisor 如何使用热部署可以参考这里:http://www.cnblogs ...

  4. win7记事本txt图标显示异常解决方法

    链接:https://zhidao.baidu.com/question/2076205353435701108.html                                       ...

  5. Eclipse之maven插件link方式安装

    maven是开发人员要具备的必不可少的技能之一.在使用eclipse进行开发时,我们需要安装maven插件,网上有很多教程,但是有些教程写的太过模糊.在此,我将自己的安装方法总结一下,尽量细致. 前提 ...

  6. if语句学习

    #print("您好,我叫周星驰") ''' x=1+2+3 print(x*4) print(x**x) a=input("请输入相应的数字a") a=int ...

  7. Python3基础 list pop(含参) 取出列表中的指定索引的元素

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Dart语言快速学习上手(新手上路)

    Dart语言快速学习上手(新手上路) // 声明返回值 int add(int a, int b) { return a + b; } // 不声明返回值 add2(int a, int b) { r ...

  9. 转载:Systemd 服务配置文件

    目录 一.开机启动 二.启动服务 三.停止服务 四.读懂配置文件 五. [Unit] 区块:启动顺序与依赖关系. 六.[Service] 区块:启动行为 6.1 启动命令 6.2 启动类型 6.3 重 ...

  10. Oracle用户被锁定解决方法

    解决方法: 1.用dba角色登陆:2.输入下面格式命令解锁: alter user 用户名 account unlock;3.如果密码忘记了,输入下面格式命令修改密码: alter user 用户名 ...