gargari专题

codeforces 463D Gargari and Permutations

题意: 从所给的序列中找出它们的最长公共子序列。 思路: DAG(有向无环图)+BFS。 如果数值 i 在所有序列中都在 j 前面。则i -> j连一条有向边。(好像还有个dp的思路的) 参考:http://www.cnblogs.com/hujunzheng/p/3947392.html AC代码: #include <cstdio>#include <cstring>#i

Codeforces 463C Gargari and Bishops

题意: 在一个n*n的矩阵中,让你选择两个点,使得两点所在的主对角线和斜对角线所包含的元素值之和最大。两点的对角线不能相交于同一个点。 思路: 一开始就被不能相交于同一个点难住了。后来问了铭神,二维矩阵其实是个二分图,就好比黑白染色。 先预处理出两种对角线的和,根据下面两条性质。 主对角线:横纵坐标相减的结果是相等的。 斜对角线:横纵坐标的和是相等的。 横纵坐标的和的奇偶性决定它们的

Codeforces #264 (Div. 2) D. Gargari and Permutations

Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have foundk permutations. Each of them consists of number

codeforces C#264. Gargari and Bishops

Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n × n chessboard. Each cell of the chessboard has a number written on