HDU 4436 str2int(后缀自动机)】的更多相关文章

str2int \[ Time Limit: 3000 ms\quad Memory Limit: 131072 kB \] 题意 给出 \(n\) 个串,求出这 \(n\) 个串所有子串代表的数字的和. 思路 首先可以把这些串合并起来,串与串之间用没出现过的字符分隔开来,然后构建后缀自动机,因为后缀自动机上从 \(root\) 走到的任意节点都是一个子串,所有可以利用这个性质来做. 一开始我的做法是做 \(dfs\),令 \(dp[i]\) 表示节点 \(i\) 的贡献,转移就是 \(dp[v…
str2int Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2082    Accepted Submission(s): 744 Problem Description In this problem, you are given several strings that contain only digits from '0'…
Problem Description In this problem, you are given several strings that contain only digits from '0' to '9', inclusive.An example is shown below.101123The set S of strings is consists of the N strings given in the input file, and all the possible sub…
str2int Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on HDU. Original ID: 443664-bit integer IO format: %I64d      Java class name: Main In this problem, you are given several strings that contain only digits from '0' to '9',…
模板来源:http://blog.csdn.net/zkfzkfzkfzkfzkfzkfzk/article/details/9669747 解法参考:http://blog.csdn.net/dyx404514/article/details/9631787 刚学后缀自动机,还是有很多性质不是很了解……目前也就能做个模板题orz #include<cstdio> #include<cstring> #include<cstdlib> #include<algor…
Reincarnation Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Problem Description Now you are back,and have a task to do:Given you a string s consist of lower-case English letters only,denote f(s) as the number of…
Typewrite \[ Time Limit: 1500 ms\quad Memory Limit: 262144 kB \] 题意 给出一个字符串 \(s\),现在你需要构造出这个字符串,你每次可以花费 \(q\) 在末尾加上任意一个字符或者花费 \(p\) 复制任意一段已经构造出来的子串到末尾,问最少需要花费多少. 思路 令 \(dp[i]\) 表示构造到第 \(i\) 位最少花费多少. 第一种情况,直接花费 \(q\) 添加在末尾,\(dp[r] = dp[r-1]+q\) 第二种情况,…
Reincarnation \[ Time Limit: 3000 ms\quad Memory Limit: 65536 kB \] 题意 给出一个字符串 \(S\),然后给出 \(m\) 次查询,每次给出一个 \([l, r]\) 区间,每次求出这个区间内有多少个不同的子串. 思路 首先知道给出一个字符串,如何求出其不同子串的个数,有三种方法. 利用后缀数组,\(\sum_{i=2}^{n} len-sa[i]+1-height[i]\) 就是答案 利用后缀自动机,\(dp[i]\) 表示第…
Good Article Good sentence \[ Time Limit: 3000 ms\quad Memory Limit: 32768 kB \] 题意 给出一个 \(S\) 串,在给出 \(n\) 个 \(T\) 串,求出 \(S\) 串中有多少子串没有在任意一个 \(T\) 串中出现过 思路 \(\quad\) 首先可以对 \(S\) 串构建后缀自动机,然后在插入 \(n\) 个 \(T\) 串,每两个串之间用 \(27\) 隔开,然后可以求出这个自动机上每个节点出现的最左位置…
题目链接 题意:你要打印一段字符串,往尾部添加一个字符需要花费p元,复制一段字符到尾部需要花费q元,求打印完全部字符的最小花费. 一开始想的贪心,后来发现忘了考虑p<q的情况了,还纳闷怎么不对..(囧) 设$dp[i]$为打印完前i个字符的最小花费 第一种转移是$dp[i+1]=min(dp[i+1],dp[i]+p)$,可以直接转移 第二种转移是$dp[j]=min(dp[j],dp[i]+q)$,对于每个i需要找到最大的j,使得$s[i+1,j]$是$s[1,i]$的子串.说到子串,就自然能…