传送门:CodeForces-1006F
思路分析
一次DFS的复杂度是$2^40$,两次的话是$2*2^20$
从头和从尾开始,跑到相同点的时候统计答案
样例输入
3 3 11
2 1 5
7 10 0
12 6 4
样例输出
3
AC代码
#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
bool IOerror=0;
inline char nc() {
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if(p1==pend) {
p1=buf;
pend=buf+fread(buf,1,BUF_SIZE,stdin);
if(pend==p1) {
IOerror=1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) {
return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
}
template<class T> inline bool read(T &x) {
bool sign=0;
char ch=nc();
x=0;
for(; blank(ch); ch=nc());
if(IOerror)return false;
if(ch=='-')sign=1,ch=nc();
for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
if(sign)x=-x;
return true;
}
template<class T,class... U>bool read(T& h,U&... t) {
return read(h)&&read(t...);
}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 0x3f3f3f3f;
int n,m;
ll a[22][22];
map<ll,ll>dp[22][22];
void dfs1(int x,int y,ll s){
if(x>n||x<1||y>m||y<1) return ;
s^=a[x][y];
if(x+y==(n+m)/2+1) {
dp[x][y][s]++;
return ;
}
dfs1(x+1,y,s);
dfs1(x,y+1,s);
}
ll dfs2(int x,int y,ll s){
if(x>n||x<1||y>m||y<1) return 0;
if(x+y==(n+m)/2+1) return dp[x][y][s];
s^=a[x][y];
return dfs2(x-1,y,s)+dfs2(x,y-1,s);
}
int main() {
#ifdef xiaofan
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
ll k;
read(n,m,k);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) read(a[i][j]);
dfs1(1,1,0);
cout<<dfs2(n,m,k)<<endl;
return 0;
}