Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appoin…
大意: 给定m个n排列, 求有多少个公共子串. 枚举每个位置, hash求出最大匹配长度. #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <strin…
题目传送门 题目大意: 给出m个1-n的全排列,问这m个全排列中有几个公共子串. 思路: 首先单个的数字先计算到答案中,有n个. 然后考虑多个数字,如果有两个数字相邻,那么在m个串中必定都能找到这两个数字并且位置相邻.那么我们枚举1-n所有的数字,比如先枚举p1是1,那p2就是在全排列1中p1后面的数字,然后往下面找,看看下面的全排列,p2是不是也在p1的后面,如果是的话,再看p3是不是在p2的后面. 要注意的是,如果我们发现p2在p1的后面,那么我们就把p1p2连起来,合并到dp[1][p1]…
[题目] D. Mysterious Crime [描述] 有m个n排列,求一共有多少个公共子段. 数据范围:1<=n<=100000,1<=m<=10 [思路] 对于第一个排列来说,如果第k个位置开始往后L长的子段是一个公共的子段,那么从k开始往后数1,2,...,L-1长的子段都是公共的子段:如果第k个位置开始往后L长的子段是一个公共的子段,但第k个位置开始往后L+1长的子段不是一个公共的子段,那么位置k到位置k+L中任一位置j开始往后直到位置k+L的子段都不是公共的子段.这就…
[链接] 我是链接,点我呀:) [题意] 相当于问你这m个数组的任意长度公共子串的个数 [题解] 枚举第1个数组以i为起点的子串. 假设i..j是以i开头的子串能匹配的最长的长度. (这个j可以给2..m这些数组用一个类似链表的东西很快得到,O((j-i+1)M)的复杂度即可完成. 那么我们会发现,我们不需要重新再从i+1开始枚举. 因为i..j这一段的任意一个子串都是满足要求(公共子串)的. 而它有len(1+len)/2个子串 那么我们从j+1开始继续上述步骤就Ok了. 注意m=1的时候..…
题目 题意: 在m组数,每组有n个数(数的范围1-n)中,找到某些序列 使它是每组数的一个公共子序列,问这样的某些序列的个数? 思路: 不难想出答案ans是≥n的. 创立一个next数组,使每组中第i个数的next 是第i+1个数,即 nex[ a[i] ] = a[ i+1 ] (实际上设next是二维数组).对第一组中的第i个数,如果在其余每组的next[ a[ i ] ]都是等于第一组中a[ i+1 ]的,意味着序列 a[ i ],a[ i+1 ]是一个公共子序列.       利用一个数…
链接 [http://codeforces.com/contest/1043/problem/D] 题意 给你一个m*n的矩阵(m<=10,n<=1e5), 每一行的数字是1到n里不同的数字 问你这m行中有多少个公共子序列 分析 用一个二维数组保存每一行的每个位置的数字的前面一个数字是什么, 然后后面用最后一行的数字和前面每一行对比,统计就好了,具体看代码就很容易理解了 还有一个组合数学的东西看下面图片就好了 代码 #include<bits/stdc++.h> using nam…
Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster e…
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are nn bricks lined in a row on the ground. Chouti has got mm paint buckets of different colors at hand, so he painted each brick in on…
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but…