• Codeforces 1006 F


    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 = 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
    ", ans);
        return 0;
    }
  • 相关阅读:
    Leecode no.22 括号生成
    修改mysql数据库的时区
    Django 路由层之反向解析
    学习 Django 的几个教程网址
    leetcode周赛 242
    AcWing第二次热身赛
    AcWing夏季每日一题--最长公共子序列
    AcWIng夏季每日一题--序列最大收益
    leetcode周赛 241
    第十二届蓝桥杯C++ B组
  • 原文地址:https://www.cnblogs.com/widsom/p/9321699.html
Copyright © 2020-2023  润新知