Codeforces 1006 F - Xor-Paths
思路:
双向搜索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的更多相关文章
- codeforces 1006 F(折半搜索)
F. Xor-Paths time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- [codeforces 293]B. Distinct Paths
[codeforces 293]B. Distinct Paths 试题描述 You have a rectangular n × m-cell board. Some cells are alrea ...
- Codeforces 835 F. Roads in the Kingdom
\(>Codeforces\space835 F. Roads in the Kingdom<\) 题目大意 : 给你一棵 \(n\) 个点构成的树基环树,你需要删掉一条环边,使其变成一颗 ...
- Codeforces 731 F. Video Cards(前缀和)
Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...
- 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 ...
- Codeforces 1005 F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路: bfs+dfs 首先,bfs找出1到其他点的最短路径大小dis[i] 然后对于2...n中的每个节点u,找到它所能改变的所 ...
- Codeforces 617 E. XOR and Favorite Number
题目链接:http://codeforces.com/problemset/problem/617/E 一看这种区间查询的题目,考虑一下莫队. 如何${O(1)}$的修改和查询呢? 令${f(i,j) ...
- Codeforces 627 A. XOR Equation (数学)
题目链接:http://codeforces.com/problemset/problem/627/A 题意: 告诉你s 和 x,a + b = s a xor b = x a, b > ...
随机推荐
- 观实验室PPT演讲有感
outline 一定要有 说话的语速要慢,压制住紧张的心情 提前一天发布PPT dont` argue with audience, especially professor and teachers ...
- linux /Android 平台下使用 i2c-tools
下载源码将 i2c-tools 代码下载到 Android 源码的 external 目录下 在 i2c-tools 目录下新建 Android.mk 文件,内容如下: # external/i2c- ...
- Codeforces 917F Substrings in a String - 后缀自动机 - 分块 - bitset - KMP
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字母串,要求支持以下操作: 修改一个位置的字母 查询一段区间中,字符串$s$作为子串出现的次数 Solution 1 Bitset 每 ...
- luogu P5105 不强制在线的动态快速排序
前言 考试的时候居然想错了区间贡献,mdzz 思路 题目看着很方啊,难道要树套树? 但数据范围提醒我们,是nlogn的复杂度 Sort(S)的定义是不是很鬼畜 但我们不动脑子的打表容易发现 连续区间[ ...
- SSM项目问题中遇到 ArrayList添加元素的问题
记录项目开发中 一次有趣的debug经历 本来是在做单元测试的,但是发现如下代码 有问题.. ProductCategory p = new ProductCategory(); for (int i ...
- office完全卸载
第一步:先暂停office服务,再通过 控制面板--卸载程序 --卸载office应用 第二步:通过office_move(自己命名的工具)软件卸载 工具分享:https://pan.baidu. ...
- WebLogic调用WebService提示Failed to localize、Failed to create WsdlDefinitionFeature
在本地Tomcat环境下调用WebService正常,但是部署到WebLogic环境中,则提示警告:[Failed to localize] MEX0008.PARSING_MDATA_FAILURE ...
- HDFS 的垃圾回收配置
HDFS的垃圾回收 的默认配置的 0,也就是说,如果你不小心误删除了某样东西,那么这个操作是不可恢复的. 但是如果配置了HDFS的垃圾回收机制,那么删除的东西就可以在垃圾箱中保存一段你配置的时间,等 ...
- Using git-flow to automate your git branching workflow
Using git-flow to automate your git branching workflow Vincent Driessen’s branching model is a git b ...
- Docker Engine SDKs and API 的开发1
Develop with Docker Engine SDKs and API Docker provides an API for interacting with the Docker daemo ...