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 ...
随机推荐
- 【bzoj2815】[ZJOI2012]灾难 拓扑排序+倍增LCA
题目描述(转自洛谷) 阿米巴是小强的好朋友. 阿米巴和小强在草原上捉蚂蚱.小强突然想,果蚂蚱被他们捉灭绝了,那么吃蚂蚱的小鸟就会饿死,而捕食小鸟的猛禽也会跟着灭绝,从而引发一系列的生态灾难. 学过生物 ...
- [洛谷P1337][JSOI2004]平衡点 / 吊打XXX
题目大意:有$n$个重物,每个重物系在一条绳子上.所有绳子系在一起,问绳结最终平衡于何处. 题解:$NOIP$前学学模拟退火,但发现我脸好黑啊... 卡点:脸黑 C++ Code: #include ...
- TextView AutoLink, ClikSpan 与长按事件冲突的解决
前言 首先,我们先来复习一下 autoLink 和 ClickableSpan 是干什么用的. autoLink 当中有五个属性值:分别是 phone.email.map.web.all 和 none ...
- hdu4418 Time travel 【期望dp + 高斯消元】
题目链接 BZOJ4418 题解 题意:从一个序列上某一点开始沿一个方向走,走到头返回,每次走的步长各有概率,问走到一点的期望步数,或者无解 我们先将序列倍长形成循环序列,\(n = (N - 1) ...
- BZOJ1407 [Noi2002]Savage 【扩展欧几里得】
题目链接 BZOJ1407 题解 枚举\(m\)用扩欧判即可 #include<algorithm> #include<iostream> #include<cstrin ...
- wya费用流
#include<bits/stdc++.h> using namespace std; #define M 1005 #define inf 0x7fffffff #define T 6 ...
- [hdu 2102]bfs+注意INF
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的……把INF改成I ...
- recycleview的基础Adapter
.封装了一个基础的adapter.,用于recycleview的快捷使用有BaseAdapter,BaseViewHolder,PAdapter,MainActivity public abstrac ...
- Google File System中文版
英文原文地址: Google File system 译文原文地址: The Google File System中文版 Google File System中文版 摘要 我们设计并实现了Google ...
- Maven 标准目录结构
Maven 标准目录结构 好的目录结构可以使开发人员更容易理解项目,为以后的维护工作也打下良好的基础.Maven2根据业界公认的最佳目录结构,为开发者提供了缺省的标准目录模板.Maven2的标准目录结 ...