Problem Description MZL's Circle Zhou is good at solving some counting problems. One day, he comes up with a counting problem:You are given two strings a,b which consist of only lowercase English letters. You can subtract a substring x (maybe empty)…
Description Input Output Sample Input Sample Output Solution 题意:给你两个串,分别从两个里面各选出一个子串拼到一起,问能构成多少个本质不同的字符串. 首先考虑一下,什么时候一个串会被重复计算. 例如假设串$abcad$,可以由$ab+cad$或$a+bcad$组成. 第一个串中可以用$ab$,也可以用$a$.$a$可以构成$abcad$,那么$ab$也能构成$abcad$. 也就是说,我们要在第一个串中找一个最靠右的,然后再到第二个串…
MZL's Circle Zhou 题意:给定两个长度不超过a,b(1 <= |a|,|b| <= 90000),x为a的连续子串,b为y的连续子串(x和y均可以是空串):问x+y形成的不同串的个数? 误区:开始一门心思想着求出总的可形成的字符串个数,再减去a,b中相同的子串重叠的部分:想通过连续插入a+b得到的SAM并不能获得信息:因为x,y是任意的子串,连续插入导致一定是a的后缀和b的前缀 正解:直接在计算有不同子串时,就不去计算重复的 <=>对于一个可能出现x后缀和y前缀相同…
题目大意: 给你两个字符串a和b,从中分别取出子串x和y,求不同的x+y的个数. 思路: 对于每一个字符串,构建SAM. 为了保证相同的x+y不会被重复统计,我们可以想办法只统计相同的x+y中x最长的一种情况. 考虑在SAM上DP. 用DFS对a的SAM进行遍历,若当前遍历到的串x不能加上字符c时,在b的SAM中寻找以c开头的y,显然对于这样的x+y,x一定是最长的. 然后用G++交到HDU上发现TLE了. 觉得是自己DFS哪里死循环了,未果. 感觉是被卡常数,用C++交了一发,WA. 觉得自己…
MZL's Circle Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description   MZL's Circle Zhou is good at solving some counting problems. One day, he comes up with a counting problem:You are given two…
MZL's Circle Zhou Time Limit: 1000ms Memory Limit: 131072KB This problem will be judged on HDU. Original ID: 534364-bit integer IO format: %I64d      Java class name: Main   MZL's Circle Zhou is good at solving some counting problems. One day, he com…
A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer…
Pascal's Travels Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description An n x n game board is populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate pat…
题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5535   Accepted: 2500 Description An n x n game board is populated with integers, one nonnegative integer per square. The goal is to tr…
1.直接用递归函数计算状态转移方程,效率十分低下,可以考虑用递推方法,其实就是“正着推导,逆着计算” #include<iostream> #include<algorithm> using namespace std; #define maxn 1000+5 int n; int a[maxn][maxn]; int d[maxn][maxn]; int main(){ for(;cin>>n && n;){ memset(d,,sizeof(d));…