题意略。

思路:

双向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. 《VR入门系列教程》之17---发布第一个应用

    发布运行     Unity可以支持多种目标平台的发布,包括:桌面端.Web端.移动端.游戏主机端.     发布运行之前的Cubes场景至桌面端,我们先选择File->Build Settin ...

  2. SpringMVC表单对象绑定到@ModelAttribute

    支持绑定表单对象 jsp: <%@ taglib prefix="form" uri="http://www.springframework.org/tags/fo ...

  3. spring与actionMQ整合

    出处:http://www.cnblogs.com/leiOOlei/p/5075402.html 一.配置部分 ActiveMQ的安装这就不说了,很简单, 这个例子采用maven构建,首先看一下po ...

  4. 脱壳系列_2_IAT加密壳_详细版_解法1_包含脚本

    1 查看壳程序信息 使用ExeInfoPe 分析: 发现这个壳的类型没有被识别出来,Vc 6.0倒是识别出来了,Vc 6.0的特征是 入口函数先调用GetVersion() 2 用OD找OEP 拖进O ...

  5. 【iOS】NSNotification 常用方法

    NSNotification 常用的几个方法,代码如下: // 发送通知 [[NSNotificationCenter defaultCenter] postNotificationName:@&qu ...

  6. 【NOI 2015】程序自动分析 并查集与离散化处理

    题目描述 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3,-代表程序中出现的变量,给定n个形如xi=xj或xi≠xj的变量 ...

  7. selenium定时签到程序

    selenium定时签到程序 定时任务 # -*- coding: utf-8 -*- import time import os import sched import datetime from ...

  8. 用 PYQT5 和 QT Dseingner 写的串口助手

    最近公司做项目需要写串口助手,于是从网上找教程着手写了一下,基本的功能可以实现了,但是想要一个表盘的功能一直没有找到教程,有些遗憾.大神们会的话给指导指导  谢谢啦 ! 下边有源码的连接,欢迎大家下载 ...

  9. 夯实Java基础(十)——抽象类和接口

    转载自:http://cmsblogs.com/ 该博主的网站上干货非常!非常!非常多(说三遍),强烈推荐大家前去学习. 接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法 抽象类与接口是 ...

  10. 深入剖析 RabbitMQ —— Spring 框架下实现 AMQP 高级消息队列协议

    前言 消息队列在现今数据量超大,并发量超高的系统中是十分常用的.本文将会对现时最常用到的几款消息队列框架 ActiveMQ.RabbitMQ.Kafka 进行分析对比.详细介绍 RabbitMQ 在 ...