给出N*M矩阵,对于该矩阵有两种操作: 1.交换两列,对于整个矩阵只能操作一次 2.每行交换两个数. 交换后是否可以使每行都递增. *解法:N与M均为20,直接枚举所有可能的交换结果,进行判断 每次枚举注意列和行都可以选择不交换 #include <iostream> #include <cstdio> using namespace std; int n, m; ][]; bool check(int t)//检查第t行是否符合递增 { ; ; i < m; i++) ])…
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <c…
题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible solution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are some beautiful girls in…
B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came u…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output There are some beautiful girls in Arpa's land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number x, coun…
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that , where is bitwise xor operation (see not…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output   There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number x…
Content 有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数.其中 \(\oplus\) 表示异或符号. 数据范围:\(1\leqslant n,a_i\leqslant 10^5,0\leqslant x\leqslant 10^5\). Solution 利用一个异或的性质:\(a\oplus b=c\Rightarrow a\oplus c=b,b\oplus c=a\),我们发现问题…
codeforces 741D Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 题意 给出一棵树,每条边上有一个字符,字符集大小只有22. 对于每一个子树,询问其中最长的,满足:路径上的字符集可以重组成字符串的路径的长度. 题解 明显是用mask维护信息,然后启发式合并一下. 一般启发式合并需要用map维护信息,这样的复杂度是log^2的.如果保留每个点重儿子的信息,就可以用全局变量维护,全局变量的大小就可以开很大,可以做到l…
题目链接:Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 第一次写\(dsu\ on\ tree\),来记录一下 \(dsu\ on\ tree\)主要维护子树信息,往往可以省掉一个数据结构的启发式合并.大体思路如下: 轻重链路径剖分之后,对每个点先递归处理他的所有轻儿子,每次处理完轻儿子之后把这棵子树的信息清空.最后再来处理重孩子,重儿子的信息就可以不用清空了.由于我们是用一个全局数组来记录信息的,重儿子子树的信息就仍然保留…
[题目链接] http://codeforces.com/problemset/problem/741/B [题目大意] 给出一张图,所有连通块构成分组,每个点有价值和代价, 要么选择整个连通块,要么只能在连通块中选择一个,或者不选,为最大价值 [题解] 首先我们用并查集求出连通块,然后对连通块进行分组背包即可. [代码] #include <cstdio> #include <vector> #include <algorithm> #include <cstr…
题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #include <stdio.h> #include <algorithm> #include <string.h> #include <vector> using namespace std; + ; int w[N],b[N]; int n,m,W; int r…
题意:求1378 n次幂的最后一位. 析:两种方法,第一种,就是快速幂,第二种找循环节,也很好找,求一下前几个数就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #…
<题目链接> 题目大意: 就是有n个人,每个人都有一个体积和一个价值.这些人之间有有些人之间是朋友,所有具有朋友关系的人构成一组.现在要在这些组中至多选一个人或者这一组的人都选,在总容量为W的情况下,如何使得所选人的价值总和最大. 解题分析: 很明显有朋友关系的人需要用DFS或者并查集进行分组.考虑全选这一组的情况,需要将这一组的人打包,看成一个人,然后塞入对应的组中.之后的分组背包就能够实现全选这一组的人的情况. #include <bits/stdc++.h> using na…
感觉dsu on tree一定程度上还是与点分类似的.考虑求出跨过每个点的最长满足要求的路径,再对子树内取max即可. 重排后可以变成回文串相当于出现奇数次的字母不超过1个.考虑dsu on tree,容易想到遍历时记录每种情况的最大深度,合并时类似点分的逐个计算贡献再合并即可.这里有个问题是得到某子树信息后,对于原来的根来说,这个信息还要再加上一个偏移量,但直接暴力显然复杂度就不对了.实际上维护信息过程中不断传递偏移量即可. 一开始就发现了这个题只开了256M,于是机智的开了个map,悲惨的T…
题目链接 \(Description\) 给定一棵树,每条边上有一个字符(a~v).对每个节点,求它的子树中一条最长的路径,满足 路径上所有边上的字符可以重新排列成一个回文串.输出其最长长度. \(n\leq 5\times10^5\). \(Solution\) 可以构成回文串,即要么所有字符都出现了偶数次,要么有一个出现了奇数次.其余都出现了偶数次. 转化为异或!把每个字符c(0~21)映射到1<<c上去. 令\(s[x]\)表示根节点到\(x\)路径上边权的异或和.那么路径\((u,v)…
题目链接:http://codeforces.com/contest/742/problem/C C. Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you have noticed, there are lovely girls in Ar…
题目链接:http://codeforces.com/contest/742/problem/D D. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Just to remind, girls in Arpa's lan…
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided…
C. Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered fro…
D - Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 思路: 树上启发式合并 从根节点出发到每个位置的每个字符的奇偶性记为每个位置的状态,每次统计一下每个状态的最大深度 为了保证链经过当前节点u,我们先计算每个子树的答案,再更新子树状态对深度的贡献. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bit…
D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满足这个边上的所有字母重拍后可以构成回文 发明者自己出的题...orz 由于本来知道就是dsu on tree,所以还是想出来了 首先点分治是没法做了,这是有根树 写成二进制,两条链合起来构成回文\(\rightarrow\)异或和为0或者只有一位是1 一开始困惑于只处理到当前根的异或和的话,随着当前…
D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths http://codeforces.com/problemset/problem/741/D 题意: 一棵根为1 的树,每条边上有一个字符(a-v共22种). 求每个子树内的最长的路径,使得路径上的边按照一定顺序排列后是回文串. 分析: dsu on tree.询问子树信息. 首先将这22个字符,转化为二进制.a=1,b=10,c=100...如果一条路径可以是回文串,那么…
Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you have noticed, there are lovely girls in Arpa's land. People in Arpa's land are numbered from 1…
Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hose…
Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1…
CF741C - Arpa's overnight party and Mehrdad's silent entering 题意: 有 n 对情侣坐成一个圈,有两种食物Kooft and Zahre-mar,要给每个人分其中一种,要求每对情侣的食物不同,任意连续的三个人必须要有两人食物不同. 求分配方案,无解输出-1 1≤n ≤100000 注意:"Kooft" is something make people die. "Zahre-mar" meaning is…
CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 好像这个题只能Dsu On Tree? 有根树点分治 统计子树过x的路径 奇偶可以xor,深度可以减,所以,w[x]x到根的链上二进制数S保留字符出现奇偶性 mx[S]表示w[x]=S的x的最大深度 类比点分治去做 更新答案时候处理一个轻儿子回来更新mx[] 重儿子贡献的答案额外处理. #include<bits/stdc++.h> #define reg reg…
B. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some H…
C. Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output As you have noticed, there are lovely girls in Arpa's land. People in Arpa's land are numbered fro…