Codeforces 1010F Xor-Paths 【搜索】【暴力!】

 1 #include<iostream>
 2 #include<map>
 3 using namespace std;
 4
 5 long long a[25][25],ans,k,x1[25];
 6 int n,m,mid;
 7
 8 map<long long, int> mp[25][25];
 9
10 void dfs1(int x,int y,long long k1,int cnt){//从x,y的位置搜到中间行  == k1是一路上^得到的数 包括(x,y)
11     if(cnt==mid) mp[x][y][k1]++;
12     else if(y==m) dfs1(x+1,y, k1^a[x+1][y],cnt+1 );
13     else if(x==n) dfs1(x,y+1, k1^a[x][y+1],cnt+1 );
14     else { dfs1(x+1,y,k1^a[x+1][y],cnt+1); dfs1(x,y+1,k1^a[x][y+1],cnt+1); }
15 }
16
17 void dfs2(int x,int y,long long k1,int cnt){//从x,y的位置搜到第(n+1)/2行  == k1是一路上^得到的数,但没有包括(x,y)
18      if(cnt==n+m-2-mid) ans+=mp[x][y][k^k1];
19     else if(y==1) dfs2(x-1,y, k1^a[x][y],cnt+1 );
20     else if(x==1) dfs2(x,y-1, k1^a[x][y],cnt+1 );
21     else { dfs2(x,y-1,k1^a[x][y],cnt+1); dfs2(x-1,y,k1^a[x][y],cnt+1); }
22 }
23
24 int main(){
25     cin>>n>>m>>k;
26     for(int i=1;i<=n;i++)
27         for(int j=1;j<=m;j++) cin>>a[i][j];
28
29     mid=(n+m-2)/2;//一共要走n+m-2次,走了一半的次数走到哪哪就定义成中间行的一部分
30     //从(1,1)搜到中间那一行
31     dfs1(1,1,a[1][1],0);
32     //从(n,m)搜到中间那一行
33     dfs2(n,m,0,0);
34     cout<<ans;
35     return 0;
36 }

原文地址:https://www.cnblogs.com/ZhenghangHu/p/9329236.html

时间: 2024-08-10 23:50:17

Codeforces 1010F Xor-Paths 【搜索】【暴力!】的相关文章

Codeforces 443A Borya and Hanabi(暴力)

题目链接:Codeforces 443A Borya and Hanabi 题目大意:有若干个牌,每张牌有花色和数字两个值,现在问说至少询问多少次才能区分出所有的牌,每次询问可以确定一种花色牌的位置,或者是一种数字牌的位置. 解题思路:暴力枚举需要问的花色和数字,210,然后枚举两两判断是否可以被区分. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const

Codeforces 14D Two Paths 树的直径

题目链接:点击打开链接 题意:给定一棵树 找2条点不重复的路径,使得两路径的长度乘积最大 思路: 1.为了保证点不重复,在图中删去一条边,枚举这条删边 2.这样得到了2个树,在各自的树中找最长链,即树的直径,然后相乘即可 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #includ

Codeforces 850A - Five Dimensional Points(暴力)

原题链接:http://codeforces.com/problemset/problem/850/A 题意:有n个五维空间内的点,如果其中三个点A,B,C,向量AB,AC的夹角不大于90°,则点A是"bad"的否则是"good".题目让我们输出good的点. 思路:从2,3维空间超过5,7个点时不存在"good"的点,可以简单推知五维空间内,超过11个点时不存在"good"的点,那么点数小于11时暴力,大于11时输出0. 其

Codeforces Gym 100203G Good elements 暴力乱搞

原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以我们需要记录所有的ai+aj,如果当前考虑到了ak,那么就去前面寻找ai,使得ak-ai是我们记录过的和.整个算法的复杂度O(n^2). 代码 #include<iostream> #include<cstring> #include<cstdio> #include<

CodeForces 374C 记忆化搜索

/*题目*/ 题意:Inna喜欢Dima,所以他希望在一张n * m的 每个单元格印有'D'或者'I'或者'M'或者'A' 的桌子上  尽量多的走出 某个路径 中包含DIMA 这个单词数量最多,必须从'D'开始走,并且'D'只能到'I',然后'I'只能到'M',然后'M'只能到'A',然后'A'只能到'D',这样走, 若走不出DIMA这个单词 输出 poor dima 若存在环的话 输出 poor Inna 否则输出 走的路径中 包含 的最多的DIMA单词数量 他奶奶的 一开始,对于那个判断环的

Codeforces Gym 100637G G. #TheDress 暴力

G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G Description After landing on planet i1c5l people noticed that blue and black clothes are quite popular among the locals. Each aboriginal has at least

Codeforces gym 100685 A. Ariel 暴力

A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Description King Triton really likes watching sport competitions on TV. But much more Triton likes watching live competitions. So Triton decides to set up

Codeforces 839D Winter is here - 暴力 - 容斥原理

Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a m

Codeforces#498F. Xor-Paths(折半搜索)

time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output There is a rectangular grid of size n×mn×m. Each cell has a number written on it; the number on the cell (i,ji,j) is ai,jai,j. Your task is