链接:Codeforces 1006F - Xor-Paths
大意:给你一个n*m的矩阵,矩阵上每一点都有一个值,求该矩阵从(1,1)到(n,m)的所有路径中,有多少条路径上值的异或和等于k。(1<=n,m<=20,1<=ai,k<=1e18)
思路:首先想到的是朴素的dp或bfs搜索所有路径,当值相等时记录+1即可,但显然空间复杂度或时间复杂度太高了,所以我们考虑将路径拆分为两半,分别从左上和右下开始搜索,直到两者相遇时,用map记录判断有多少值相等,输出最后结果即可。
代码:
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
using namespace std;
struct pos
{
int x, y;
pos(int x, int y)
{
this->x = x;
this->y = y;
}
};
int n, m;
bool visited[20][20];
long long res, k, matrix[20][20];
queue<pos*> bfq;
vector<long long> xor_sum[20][20];
map<long long, long long> equals;
void bfslt()
{
xor_sum[0][0].push_back(matrix[0][0]);
bfq.push(new p