zoukankan      html  css  js  c++  java
  • F. Xor-Paths 题解(折半搜索)

    题目链接

    题目思路

    最多走40步即(2^{40}),那么对于这种题目就可以使用折半搜索

    代码

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define debug printf(" I am here
    ");
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int,int> pii;
    mt19937 rnd(time(0));
    const ll INF=0x3f3f3f3f3f3f3f3f;
    const int maxn=20+5,inf=0x3f3f3f3f,mod=20071027;
    const double eps=1e-10;
    int n,m;
    ll k,a[maxn][maxn];
    ll ans;
    map<ll,ll> mp[maxn];
    void dfs1(int x,int y,ll now){
        if(x+y==(n+m+2)/2){
            mp[x][now]++;
            return ;
        }
        if(x<n) dfs1(x+1,y,now^a[x+1][y]);
        if(y<m) dfs1(x,y+1,now^a[x][y+1]);
    }
    void dfs2(int x,int y,ll now){
        if(x+y==(n+m+2)/2){
            ans+=mp[x][now^k^a[x][y]];
            return ;
        }
        if(x>1) dfs2(x-1,y,now^a[x-1][y]);
        if(y>1) dfs2(x,y-1,now^a[x][y-1]);
    }
    signed 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]);
            }
        }
        dfs1(1,1,a[1][1]);
        dfs2(n,m,a[n][m]);
        printf("%lld
    ",ans);
        return 0;
    }
    
    
    
    不摆烂了,写题
  • 相关阅读:
    Snuke's Subway Trip
    codevs 1606 台阶
    COGS 2334. [HZOI 2016]最小函数值
    codevs 1052 地鼠游戏
    洛谷 P1091 合唱队形
    洛谷 P1376 机器工厂
    codevs 2618 核电站问题
    vijos 1524 最小监视代价
    洛谷 P1690 贪婪的Copy
    51nod 1135 原根
  • 原文地址:https://www.cnblogs.com/hunxuewangzi/p/15157323.html
Copyright © 2011-2022 走看看