题意略。

思路:

双向bfs。

如图,对于曼哈顿距离为5的地方来说,除去两端的位置,其他位置的状态不会超过曼哈顿距离为4的地方的状态的两倍。

所以,最大曼哈顿距离为n + m。最多的状态不过2 ^ (n + m)。

这个复杂度我们不能接受,但是如果我们从两边向中间bfs的话, 每次bfs的复杂度为2 ^ ((n + m)/2)。

所以可以用双向广搜来解决。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ; struct point{
int x,y;
LL state;
point(int a = ,int b = ){
x = a,y = b;
}
point operator+ (const point& p){
return point(x + p.x,y + p.y);
}
int sum(){
return x + y;
}
bool operator< (const point& p) const{
if(x != p.x) return x < p.x;
else if(y != p.y) return y < p.y;
else return state < p.state;
}
}; point mov1[] = {point(,),point(,)};
point mov2[] = {point(-,),point(,-)}; LL board[maxn][maxn];
LL n,m,k;
map<point,LL> mp; void bfs1(point s){
int line = ((n + m)>>) + ;
s.state = board[s.x][s.y];
queue<point> que;
que.push(s);
while(que.size()){
point temp = que.front();
que.pop();
if(temp.sum() == line){
++mp[temp];
continue;
}
for(int i = ;i < ;++i){
point nxt = temp + mov1[i];
if(nxt.x > n || nxt.y > m) continue;
nxt.state = temp.state xor board[nxt.x][nxt.y];
que.push(nxt);
}
}
}
LL bfs2(point s){
LL ret = ;
int line = ((n + m)>>) + ;
s.state = k xor board[s.x][s.y];
queue<point> que;
que.push(s);
while(que.size()){
point temp = que.front();
que.pop();
if(temp.sum() == line){
ret += mp[temp];
continue;
}
for(int i = ;i < ;++i){
point nxt = temp + mov2[i];
if(nxt.x < || nxt.y < ) continue;
nxt.state = temp.state xor board[nxt.x][nxt.y];
que.push(nxt);
}
}
return ret;
} int main(){
scanf("%lld%lld%lld",&n,&m,&k);
for(int i = ;i <= n;++i){
for(int j = ;j <= m;++j){
scanf("%lld",&board[i][j]);
}
}
bfs1(point(,));
int line = ((n + m)>>) + ;
for(int i = ;i <= n;++i){
int j = line - i;
if(j <= ) continue;
board[i][j] = ;
}
LL ans = bfs2(point(n,m));
printf("%lld\n",ans);
return ;
}

Codeforces 1006F的更多相关文章

  1. [CodeForces]1006F Xor Path

    双向搜索. 水div3的时候最后一道题由于C题死活看不懂题 来不及做F了Orz.. 因为n,m是20,双向搜索一下,求个到中间的Xor值的方案,统计一下即可. 时间复杂度\(O(2^{21})\) 好 ...

  2. CodeForces - 1006F (深搜从两端向中间搜,省时)

    题意:输入n,m,k,给出一个n*m的图,里面有权值,从1,1一路异或到n,m,只能向右或向下走,等于k有多少种路径. 思路:一开始就是直接暴力写个深搜,稳稳的超时,分析一下时间复杂度.每个点有两个方 ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Linux卸载MySql——ubuntu版

    卸载mysql 1)删除mysql的数据文件 sudo rm /var/lib/mysql/ -R 2)删除mqsql的配置文件 sudo rm /etc/mysql/ -R 3)自动卸载mysql的 ...

  2. MySQL常用工具、日志及读写分离

    MySQL常用工具.日志及读写分离 1.MySQL中常用工具 1.1 mysql 1.1.1连接选项 1.1.2 执行选项 1.2 mysqladmin 1.3 mysqlbinlog 1.4 mys ...

  3. 支持微信页面右侧悬浮QQ在线客服

    使用方法: 1.将style里的css样式复制到你的样式表中 2.将body中的代码部分拷贝到你需要的地方即可 (js.图片采用绝对路径,不建议修改) <!DOCTYPE html PUBLIC ...

  4. linux初学者-MariaDB图形管理篇

     linux初学者-MariaDB图形管理篇 MariaDB不仅有文本管理方式,也有借助工具的图形管理方式.其图形管理的工具是"phpmyadmin".这个软件可以在"p ...

  5. 【MySQL】目录、文件权限问题

    详情如下: $ cat /usr/local/mysql/data/Phoenix-slow.log cat: /usr/local/mysql/data/Phoenix-slow.log: Perm ...

  6. Vue项目的创建和UI资源

    Vue项目创建打包与UI资源 1.Vue项目创建 1.1 vue-cli脚手架 vue-cli是一个基于vue的构建工具,用于搭建vue项目的环境,有着兼容,方便,快速的优点,能够完全遵循前后端分离的 ...

  7. QScintilla下载与编译

    你好,我是大贺! Pou光明  大家好,我又回来了~~ 之前和大家分享的是在c/c++中通过python c api嵌入python解释器,主体都是和python相关的.其实最终要和大家分享的是如何做 ...

  8. Mac环境下升级gcc版本--rocksdb

    前言 在mac环境下编译rocksdb,需要配置依赖的编译环境,其中有一项比较麻烦:c++编译要支持C++11,但是在mac环境安装xcode-select --install之后,已经安装有了gcc ...

  9. 后端基于方法的权限控制--Spirng-Security

    后端基于方法的权限控制--Spirng-Security 默认情况下, Spring Security 并不启用方法级的安全管控. 启用方法级的管控后, 可以针对不同的方法通过注解设置不同的访问条件: ...

  10. DesignPattern系列__10单例模式

    单例模式介绍 单例模式,是为了确保在整个软件体统中,某个类对象只有一个实例,并且该类通常会提供一个对外获取该实例的public方法(静态方法). 比如日志.数据库连接池等对象,通常需要且只需要一个实例 ...