Codeforces 1006 F - Xor-Paths

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 ;
}
上一篇:在android里用ExpandableListView实现二层和三层列表


下一篇:跨域之同源策略 Same-origin policy