CF#498 1006F Xor-Paths
题意:一个n * m的矩阵,求从左上走到右下经过的数异或和为k的方案数。
题解:
因为数据范围较小,所以我们可以采用meet in the middle过掉此题、、、
然而define inf LL 才过。。。。
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 22
#define LL long long
#define int LL int n, m;
LL k, ans;
LL s[AC][AC]; map<int, LL> Map[AC]; inline LL read()
{
LL x = ;char c = getchar();
while(c > '' || c < '') c = getchar();
while(c >= '' && c <= '') x = x * 10ll + c - '', c = getchar();
return x;
} void pre()
{
n = read(), m = read(), k = read();
for(R i = ; i <= n; i ++)
for(R j = ; j <= m; j ++) s[i][j] = read();
} void dfs1(int x, int y, LL now)//从左上角开始往对角线搜
{
if(x < || x > n || y < || y > m) return ;
if(x + y == (n + m + ) / ) {++ Map[x][now]; return;}
dfs1(x + , y, now ^ s[x + ][y]);
dfs1(x, y + , now ^ s[x][y + ]);
} void dfs2(int x, int y, LL now)//从右下角开始往对角线搜
{
if(x < || x > n || y < || y > m) return ;
if(x + y == (n + m + ) / ) {ans += Map[x][now ^ s[x][y]]; return ;}//不能把同一个数异或2次。
dfs2(x - , y, now ^ s[x - ][y]);
dfs2(x, y - , now ^ s[x][y - ]);
} signed main()
{
freopen("in.in", "r", stdin);
pre();
dfs1(, , s[][]);
dfs2(n, m, k ^ s[n][m]);//因为x ^ y = k ----> x ^ k = y
printf("%lld\n", ans);
fclose(stdin);
return ;
}
CF#498 1006F Xor-Paths的更多相关文章
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...
- [CodeForces]1006F Xor Path
双向搜索. 水div3的时候最后一道题由于C题死活看不懂题 来不及做F了Orz.. 因为n,m是20,双向搜索一下,求个到中间的Xor值的方案,统计一下即可. 时间复杂度\(O(2^{21})\) 好 ...
- cf 498 B. Name That Tune
不会不会,,,%%http://hzwer.com/5813.html #include<cstdio> #include<iostream> #include<algo ...
- Codeforces Round #498 (Div. 3) 简要题解
[比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements [算法] 将序列中的所有 ...
- 旧书重温:0day2【5】shellcode变形记
紧接上一篇,结合第一篇 //这篇文章主要成功溢出一个带有缓冲区溢出的小程序,其中我们的shellcode被strcpy截断了所以我们需要变形shellcode,这个实验中也出现了很多意想不到的拦路虎, ...
- CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]
D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满 ...
- CF 979D Kuro and GCD and XOR and SUM(异或 Trie)
CF 979D Kuro and GCD and XOR and SUM(异或 Trie) 给出q(<=1e5)个操作.操作分两种,一种是插入一个数u(<=1e5),另一种是给出三个数x, ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- CF 741 D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths http://codeforces.com/problemset/probl ...
随机推荐
- ROS(一)Topic 通信
ROS系统起源于2007年斯坦福大学人工智能实验室的项目与机器人技术公司Willow Garage的个人机器人项目(Personal Robots Program)之间的合作,2008年之后就由Wil ...
- PS 拉伸大长腿
1.打开一个图片工具栏--图像--画布大小 2.选择矩形选框工具--框住要拉升退的位置--然后在按Ctrl+T,进行拉伸即可
- QXDM及QCAT软件使用入门指南V1.0
链接:https://pan.baidu.com/s/1i55YXnf 密码:v6nw
- Appium(Python)驱动手机淘宝App
请注意操作步骤: 1. 用数据线连接手机, 打开开发者模式, 并赋予相关权限, 并保持不锁屏状态: 2. 启动Appium桌面服务端: 3. 运行程序: 首次运行, Appium会在手机上安装3个Ap ...
- Linux命令应用大词典-第39章 网络安全
39.1 rtacct:网络统计工具 39.2 nmap:报告远程主机特征 39.3 tcpdump:实现网络数据采集分析 39.4 iptstate:显示IP表状态表条目 39.5 nstat:监控 ...
- Java开发工程师(Web方向) - 01.Java Web开发入门 - 第3章.Tomcat
第3章--Tomcat Tomcat安装与运行 Tomcat:目前最常用的基于java的web应用服务器 本课程中所有的Java代码最终都需要部署到Tomcat中运行 Tomcat的配置文件是XML的 ...
- 使用SpringBoot整合ssm项目
SpringBoot是什么? Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. Spring Boot 现在已经成为Java ...
- TW实习日记:第13天
昨天困扰的问题终于解决了.因为是百度地图api提供的函数,所以这个解决办法并不适用于所有异步请求,仅仅针对百度地图api的调用接口函数和回调函数.有两种解决方法可以解决百度地图api中常出现的请求回调 ...
- HDU - 6440(费马小定理)
链接:HDU - 6440 题意:重新定义加法和乘法,使得 (m+n)^p = m^p + n^p 成立,p是素数.,且satisfied that there exists an integer q ...
- 基础的表ADT -数据结构(C语言实现)
读数据结构与算法分析 表的概述 形如A1,A2,A3... 操作合集 PrintList MakeEmpty Find Insert Delete 表的简单数组实现 分析: PrintList和Fin ...