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 ...
随机推荐
- netty之编解码
1.netty的编码和解码,在数据传输的时候,考虑数据安全,数据完整性都是很有必要的.这里主要是介绍netty3和netty5的编解码方式.其实从StringEncoder和StringDecoder ...
- Java 快速排序讲解
快速排序由于排序效率在同为 O(nlogn) 的几种排序方法中效率最高,因此经常被采用.再加上快速排序思想——分治法也确实非常实用,所以 在各大厂的面试习题中,快排总是最耀眼的那个.要是你会的排序算法 ...
- 使用redux-actions优化actions管理
redux-actions的api很少,有三个createAction(s) handleASction(s) combineActions 主要用到createAction去统一管理actio ...
- android分析windowManager、window、viewGroup之间关系(一)
本文将主要介绍addview方法,在windowManager.window.viewGroup中的实现原理.首先将介绍这些类结构关系,然后分析其内在联系,介绍实现原理,最后介绍重要的一个参数wind ...
- RSA加密通信小结(一)
一.背景描述 帮朋友完成相关方案的改进. 二.计划与方案 1.加密方式采用RSA 1024加密. 2.发送与接收都采用RSA加密,采用两套不同的密钥. 3.统一的加解码函数.(此处除了对于传输数据进行 ...
- 【SpringCloud 】第八篇: 消息总线(Spring Cloud Bus)
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
- python 中的reload(sys)
import sys reload(sys) sys.setdefaultencoding('utf-8') #python2中的使用方法 #重新载入 sys 模块,并设置默认编码为 utf8 & ...
- 传入中文参数-->服务器_转码的方法
如果要传入 中文参数到 服务器 使用lr_convert_string_encoding() LR_ENC_SYSTEM_LOCALE , 转为 ...
- Redis 数据结构服务器
Redis 简介 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis 与其他 key - value 缓存产品有以下三个特点: Redis支持数据的持久 ...
- 【转】MySQLroot用户忘记密码解决方案(安全模式,修改密码的三种方式)
文章出自:http://www.2cto.com/database/201412/358128.html 1.关闭正在运行的MySQL2.启动MySQL的安全模式,命令如下: ? 1 mysqld - ...