ACM-ICPC北京赛区(2017)网络赛2【后缀数组+Java//不会】
#1579 : Reverse Suffix Array
描述
There is a strong data structure called "Suffix Array" which can effectively solve string problems.
Let S=s1s2...sn be a string and let S[i,j] denote the substring of S ranging from i to j. The suffix array A of S is now defined to be an array of integers providing the starting positions of suffixes of S in lexicographical order. This means, an entry A[i] is the starting position of the i-th smallest suffix in S and thus for all 1 < i ≤ n: S[A[i-1], n] < S[A[i], n].
For example: the suffix array of “banana” is [6, 4, 2, 1, 5, 3].
Here comes another problem called "Reverse Suffix Array".
Given a suffix array, you need to figure out how many lower case strings are there whose suffix array is the same as the given suffix array.
输入
First line contains a positive number T which means the number of test cases.
For each test cases, first line contains a positive number N, the second line contains N integer(s) which indicates the suffix array A.
1 ≤ T ≤ 10, 1 ≤ N ≤ 100,000
1 ≤ A[i] ≤ N (i = 1...N)
输出
For each test case, output one line contains the answer. If no qualified string exists, output 0.
- 样例输入
-
1
5
4 3 2 5 1 - 样例输出
-
98280
【题意】:已知后缀数组,求原串的可能情况数。
【分析】:java,26^3 dp,http://blog.csdn.net/skywalkert/article/details/51731556(在 cdoj 上也有一个类似
【代码】:import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream; /**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task2 solver = new Task2();
int testCount = Integer.parseInt(in.next());
for (int i = ; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
} static class Task2 {
BigInteger C(int n, int m) {
BigInteger ans = BigInteger.valueOf();
for (int i = ; i <= m; i++) {
ans = ans.multiply(BigInteger.valueOf(n - i + ));
}
for (int i = ; i <= m; i++) {
ans = ans.divide(BigInteger.valueOf(i));
}
return ans;
} public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] a = new int[n + ];
int[] b = new int[n + ];
for (int i = ; i <= n; i++) {
a[i] = in.nextInt();
b[a[i]] = i;
}
ArrayList<Integer> arr = new ArrayList<>();
int now = ;
for (int i = ; i <= n; i++) {
if (a[i - ] != n && (a[i] == n || b[a[i - ] + ] > b[a[i] + ])) {
arr.add(now);
now = ;
} else {
now++;
}
}
arr.add(now);
if (arr.size() > ) {
out.println();
} else {
int sz = arr.size();
BigInteger[][] dp = new BigInteger[sz + ][];
for (int i = ; i <= sz; i++) {
for (int j = ; j <= ; j++) {
dp[i][j] = BigInteger.valueOf();
}
}
dp[][] = BigInteger.valueOf();
for (int i = ; i < sz; i++) {
for (int j = ; j < ; j++) {
for (int k = ; j + k <= ; k++) {
dp[i + ][j + k] = dp[i + ][j + k].add(dp[i][j].multiply(C(arr.get(i) + k - , k - )));
}
}
}
// out.println(dp[sz][26]);
BigInteger ans = BigInteger.valueOf();
for (int i = ; i <= ; i++) {
ans = ans.add(dp[sz][i]);
}
out.println(ans);
}
} } static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer; public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), );
tokenizer = null;
} public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} }
}809ms
ACM-ICPC北京赛区(2017)网络赛2【后缀数组+Java//不会】的更多相关文章
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】
题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n ...
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
- hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...
- hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...
- ACM-ICPC北京赛区(2017)网络赛_Minimum
题目9 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, -, a2^k ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum
时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 i题 Minimum(线段树)
描述 You are given a list of integers a0, a1, …, a2^k-1. You need to support two types of queries: 1. ...
- 【分类讨论】【计算几何】【凸包】hihocoder 1582 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E. Territorial Dispute
题意:平面上n个点,问你是否存在一种黑白染色方案,使得对于该方案,无法使用一条直线使得黑色点划分在直线一侧,白色点划分在另一侧.如果存在,输出一种方案. 如果n<=2,显然不存在. 如果所有点共 ...
- 【线段树】hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 I. Minimum
题意:给你一个序列(长度不超过2^17),支持两种操作:单点修改:询问区间中最小的ai*aj是多少(i可以等于j). 只需要线段树维护区间最小值和最大值,如果最小值大于等于0,那答案就是minv*mi ...
随机推荐
- C#范型实例化对象
T s = System.Activator.CreateInstance<T>();
- 【题解】SDOI2008莎拉公主的困惑
挺有趣的恩:洛谷P2155 在纸上打打草稿,写出n!个数,从先往后,遇到不互质的就筛掉——发现一个奇妙的性质!:筛掉的次数.顺序好像是周期性出现的呢~ 而且更加妙妙的是,好像还是m!一轮..那么因为n ...
- 【题解】SDOI2014数数
真的很开心呢,总算是有一道完完全全由自己做出来的题目啦~ 这一道题目洛谷P3311和另一道JSOI文本生成器的题目是十分相像的,dp方面几乎相同.只是<=n的约束,让这道题目必须结合数位dp的方 ...
- [ZJOI2005]沼泽鳄鱼 矩阵乘法
---题面--- 题解: 乍一看还是挺懵逼的.和HH去散步很像,思路也是类似的. 复制一段我在HH去散步的题解里面写的一段话吧: 考虑f[i][j]表示i和j是否右边相连,有为1,否则为0,那么f同时 ...
- [Leetcode] Reorder list 重排链表
Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You ...
- C&C++——基本说明
预处理器(Preprocessor) 1 . 用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题) #define SECONDS_PER_YEAR (60 * 60 * ...
- 一个 React & Redux的目录树
|-----------------------------------------| | | | React & Redux | | | |------------------------- ...
- Python之日志操作(logging)
import logging 1.自定义日志级别,日志格式,输出位置 logging.basicConfig( level=logging.DEBUG, format='%(asctime)s | ...
- input 只允许输入数字
onkeyup='this.value=this.value.replace(/[^0-9\-]/gi,"")'
- Ubuntu1604 install netease-cloud music
Two issue: 1. There is no voice on my computer, and the system was mute and cannot unmute. eric@E641 ...