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);
//headconst int N = 25;
LL a[N][N], k, ans = 0;
int n, m;
map<LL, LL>mp[N][N];
void dfs_pre(int x, int y, LL sum) {if(x + y == (n+m+2)/2) {mp[x][y][sum]++;return ;}if(x < n) dfs_pre(x+1, y, sum^a[x+1][y]);if(y < m) dfs_pre(x, y+1, sum^a[x][y+1]);
}
void dfs_suf(int x, int y, LL sum) {if(x + y == (n+m+2)/2) {ans += mp[x][y][sum^a[x][y]^k];return ;}if(x > 1) dfs_suf(x-1, y, sum^a[x-1][y]);if(y > 1) dfs_suf(x, y-1, sum^a[x][y-1]);
}
int main() {scanf("%d %d %lld", &n, &m, &k);for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++)scanf("%lld", &a[i][j]);}dfs_pre(1, 1, a[1][1]);dfs_suf(n, m, a[n][m]);printf("%lld\n", ans);return 0;
}

转载于:https://www.cnblogs.com/widsom/p/9321699.html

Codeforces 1006 F - Xor-Paths相关推荐

  1. CodeForces 1616H Keep XOR Low {a^b≤x} / CodeForces gym102331 Bitwise Xor {a^b≥x}(trie树 + 计数)

    文章目录 CodeForces 1616H Keep XOR Low problem solution code CodeForces gym102331 Bitwise Xor problem so ...

  2. CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换,清晰易懂)

    CodeForces - 1401 F Reverse and Swap(线段树, 区间翻转, 区间交换)   首先一共有四个操作,第一个和第四个都是线段树的基本操作,直接用线段树实现.      第 ...

  3. CodeForces 617 E. XOR and Favorite Number

    题目链接: CodeForces 617 E. XOR and Favorite Number 题目描述: 给出n个数,m次查询,每次查询在区间[l, r]里面有多少对(i, j),满足ai ^ ai ...

  4. CodeForces - 1547G How Many Paths?(强联通缩点+拓扑)

    题目链接:点击查看 题目大意:给出一张有向图,无重边,有环,现在需要判断每个点和点 111 的关系: 000:点 111 无法到达点 uuu 111:点 111 到点 uuu 有且仅有一条路径 222 ...

  5. CodeForces - 1486F Pairs of Paths(树上计数+容斥)

    题目链接:点击查看 题目大意:给出一棵 nnn 个点的树,再给出 mmm 条路径,现在问有多少个路径对 (x,y)(x,y)(x,y),满足第 xxx 条路径和第 yyy 条路径有且仅有一个交点 题目 ...

  6. Codeforces#1157 F. Ehab and the Big Finale (思维+交互题)

    链接: http://codeforces.com/contest/1174/problem/F 题意: 给你一颗树,需要你求出某个已知点,你有两种询问操作 问你能否在36次询问之内得知所求点 思路: ...

  7. 【codeforces 242E】XOR on Segment

    [原题题面]传送门 [题面翻译]传送门 [解题思路] 操作涉及到区间求和和区间异或,考虑到异或操作,我们对每个数二进制分解. 把每一位单独提出来做,异或要么取反要么变为不变,对于每一位建一颗线段树,那 ...

  8. Codeforces 835 F Roads in the Kingdom(树形dp)

    F. Roads in the Kingdom(树形dp) 题意: 给一张n个点n条边的无向带权图 定义不便利度为所有点对最短距离中的最大值 求出删一条边之后,保证图还连通时不便利度的最小值 $n & ...

  9. 【Codeforces 1426 F】Number of Subsequences,字符串计数DP

    problem F. Number of Subsequences time limit per test1 second memory limit per test256 megabytes inp ...

  10. codeforces:F. All Possible Digits【贪心 + 模拟进位】

    目录 题目截图 题目分析 ac code 总结 题目截图 题目分析 注意是只能再最后一位加 我们要使得0到p - 1都出现至少一次 统计出现的数字aset 考虑最后一位pivot 情况1:如果pivo ...

最新文章

  1. linkedlist(c语言_简单实现)
  2. 2017 9月java答案_2017年9月计算机二级JAVA试题及答案
  3. 函数模板的载体-HPP
  4. 【ArcGIS风暴】ArcGIS中等高线高程标注/注记(打断/消隐)方法案例汇总
  5. php js 图片旋转,使图片旋转的3种解决方案_基础知识
  6. 云计算OpenStack:云在身边博客园
  7. 蛮力法 —— 求解迷宫问题 —— DFS和BFS
  8. 播放量子计算机的声音,首次实现:用声音纠缠了两个量子比特!
  9. 使用Telnet客户端测试Exchange邮件收发
  10. matlab算sma,SMA_移动平均及双均线模型
  11. 为什么用Win32forth编程的程序员不多
  12. 清除 DNS 缓存( 附全平台详细教程 )
  13. Unity发布VR项目到Android
  14. 多线程的终止方法(停止线程)
  15. 强化学习(Reinforcement Learning)
  16. kinetic安装cartographer及gazebo仿真测试教程[22年1月23日测试]
  17. 基于jsp+mysql+ssm的爱康医院专家预约管理系统-计算机毕业设计
  18. 安装打印机时提示请反回上一步,使用USB数据线重新连接电脑和打印机
  19. TSO/GSO GRO/LRO 从入门到精通
  20. tomcat查看日志

热门文章

  1. Jumpserver代码规范
  2. sqlserver 备份脚本
  3. 异地备份——windows 与 linux
  4. iOS开发UI篇—UIScrollView控件实现图片缩放功能
  5. 十三、mysql 分区之 RANGE LIST
  6. Shell Notes(2)
  7. opencv findContuors 详解
  8. Android屏幕适配之--通过修改系统的屏幕像素比来实现屏幕的适配效果
  9. [PM2][ERROR] Script not found 和 npm in fork_mode
  10. elementui 日期选择值格式