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 > ...
随机推荐
- P2801 教主的魔法(分块)
P2801 教主的魔法 区间加法,区间查询 显然就是分块辣 维护一个按块排好序的数组. 每次修改依然是整块打标记,零散块暴力.蓝后对零散块重新排序. 询问时整块二分,零散块暴力就好辣 注意细节挺多和边 ...
- 教你用Visual Studio Code做PHP开发 - 微软官方工具,IDE中的黑马
转载于:http://bbs.wfun.com/thread-902655-1-1.html,仅供自己备忘 本文为我在智机网的原创 ] 关于Visual Studio Code,可能有的开发者很陌生 ...
- 使用Excel批量给数据添加单引号和逗号
表格制作过程如下: A2表格暂时为空,模板建立完成以后,用来放置原始数据: 在B2表格内输入公式: ="'"&A2&"'"&" ...
- aircrack-ng后台跑包, 成功后自动发送邮件通知
我的思路是直接用nohup守护进程输出结构到指定文件, 然后判断文件中"KEY FOUND"的字段. 启动aircrack-ng方式 nohup aircrack-ng -w /o ...
- 变参标准函数的重新封装,如printf
方法一: #include <stdio.h> #include <stdarg.h> void my_trace(const char *cmd, ...) { printf ...
- ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98) [30-Jan-2018 16:12:27] ERROR: FPM initialization failed解决方法
1.php启动之后发现访问nginx出现502错误,检查nginx.conf发现指定的php socket不存在 2.解决方法nginx修改陈这样,直接把绿色部门的socket写成本地地址+端口就可以 ...
- QML手动连接信号槽【Connections】
1.使用Connections import QtQuick 2.6 import QtQuick.Window 2.2 import QtQuick.Controls 1.4 Window { vi ...
- 前端 --- 3 css 属性
一. 标签嵌套规则 块级标签能够嵌套某些块级标签和内敛标签(行内标签) 内敛标签不能嵌套块级标签,只能嵌套内敛标签 二. 属性 1.宽和高 (块级标签能够设置高度和宽度 内敛标签不能设置,设置了没 ...
- Oracle SQL——varchar2() 和 char()关联查询 存在空格
背景 表dbcontinfo 字段loanid,类型为varchar2(60) 表dbloanbal 字段loanid,类型为char(60) loanid字段实际长度为24位 问题 两张表dbloa ...
- methods 方法选项
最简单的使用方法,一个数字,每点击一下按钮加1 html <div id="app"> <span v-text="number">&l ...