[题目链接] http://codeforces.com/problemset/problem/707/D [题目大意] 给出一个矩阵,要求满足如下操作,单个位置x|=1或者x&=0,一行的数全部取反,回到第k个操作.要求每次操作后输出这个矩阵中数字的和. [题解] 由于存在操作回溯,考虑使用可持久化数据结构或者建立离线操作树.因为懒,没写持久化.对于每个操作,将它和时间顺序上的上一个节点连边,这样子就形成了一棵树,对这棵树从根节点开始遍历,递归处理,每次处理完一棵子树就回溯操作,这样子就能离线…
题目链接: http://codeforces.com/problemset/problem/707/D 题目大意: 一个N*M的书架,支持4种操作 1.把(x,y)变为有书. 2.把(x,y)变为没书. 3.把x行上的所有书状态改变,有变没,没变有. 4.回到第K个操作时的状态. 求每一次操作后书架上总共多少书. 题目思路: [离线][深搜][树] 现场有思路不过没敢写哈.还是太弱了. 总共只用保存一张图,把操作看成一棵树,一开始I操作连接在I-1操作后,如果遇到操作4的话,把I操作与I-1操…
$dfs$,优化. $return$操作说明该操作完成之后的状态和经过操作$k$之后的状态是一样的.因此我们可以建树,然后从根节点开始$dfs$一次(回溯的时候复原一下状态)就可以算出所有状态的答案. 对于$1$和$2$操作,可以开一个数组$a[i][j]$记录每一格子被操作$1$和$2$操作了几次. 然后开一个数组$r[i]$记录每一行被操作$3$操作了几次. 每一格真正的状态为$\left( {a\left[ i \right]\left[ j \right] + r\left[ i \ri…
一个n*m的矩阵,有四种操作: 1.(i,j)处变1: 2.(i,j)处变0: 3.第i行的所有位置1,0反转: 4.回到第k次操作以后的状态: 问每次操作以后整个矩阵里面有多少个1. 其实不好处理的操作只有第四个,但是这题的思路很巧妙,123三种操作全部建立顺边,第四种操作将k和这次操作的序号建边,然后dfs进行操作即可,遇到尽头,则退回到前一个分岔点,并且回溯的过程中将操作反转. 具体见代码: #include <stdio.h> #include <algorithm> #i…
Persistent Bookcase CodeForces - 707D time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently in school Alina has learned what are the persistent data structures: they are data structures…
题目链接: D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Recently in school Alina has learned what are the persistent data structures: they are data structures that alw…
Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching…
题目链接:D Persistent Bookcase 题意:有一个n*m的书架,开始是空的,现在有k种操作: 1 x y 这个位置如果没书,放书. 2 x y 这个位置如果有书,拿走. 3 x 反转这一行,即有书的位置拿走,没书的位置放上书. 4 x 返回到第x步操作之后的书架. 现在给出q个操作,询问每次操作之后书架上书的数量. 思路: 开始没有思路.后来被告知dfs. [词不达意.参考:http://blog.csdn.net/zyjhtutu/article/details/5227949…
D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified. After reaching home Alina decided…
D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and a…