题目 传送门 题目大意 如果两个只包含数字且长度为 \(n\) 的字符串 \(s\) 和 \(w\) 存在两个数字 \(1≤i,j≤n\),使得 \(s_i<w_i,s_j>w_j\) ,则称 \(s\) 和 \(w\) 是不可比的.现在给定两个包含数字和问号且长度为 \(n\) 的字符串,问有多少种方案使得将所有问号替换成 \(0\) 到 \(9\) 的数字后两个字符串是不可比的? 思路 分析 DP 题, 我们注意到,只要有一对这样的数就可以满足条件,而等于是不属于判断情况的,因此我们要单独…
题目链接 Description Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i andj(1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s,…
最长重复字符串题解 package main import ( "fmt" "strings" ) type Index map[int]int type Counter map[string]Index var c = make(Counter) func setRecord(match string, index int) { i, ok := c[match] if !ok { i = make(Index) c[match] = i return } i[i…
A. Yaroslav and Permutations 值相同的个数不能超过\(\lfloor \frac{n + 1}{2} \rfloor\). B. Yaroslav and Two Strings 答案=总方案数-(S<=W)的方案-(W<=S)的方案+(W==S)的方案. C. Greg and Array 线段树统计每个操作的使用次数,后面就是普通区间加的线段树操作. D. Greg and Graph 反过来操作,即每次加一个点,然后更新距离和. 先计算新点到其他点的最短距离,…
题面 ARC058D Iroha Loves Strings 给定 \(n\) 个字符串,从中选出若干个按给出顺序连接起来,总长等于 \(m\),求字典序最小的,保证有解. 数据范围:\(1\le n\le 2000\),\(1\le k\le 10^4\),字符串总长 \(S\le 10^6\). 题解 atcoder 的题就是好啊,非常巧妙,毫不毒瘤. 这篇题解要抨击 Z-function 怪 ycx,造福人民. 有一个非常显然的思路:每次选当前选了的串右边没选且能选的中最小的. 这里的能选…
题解-Reachable Strings 前置知识: \(\texttt{Hash}\) Reachable Strings 给一个长度为 \(n\) 的 \(\texttt{01}\) 串 \(s\),可以让 \(s\) 中的 \(\texttt{110}\) 和 \(\texttt{011}\) 互相转换.\(q\) 次询问,每次给定两个 \(s\) 的子串 \(s_{l_1\sim l_1+len-1}\) 和 \(s_{l_2\sim l_2+len-1}\),问两个串是否可以互相变换得…
题目来源 https://leetcode.com/problems/multiply-strings/ Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 题意分析 Input: two numbers expressed as str…
题目描述 给定若干个长度小于等于10^6的字符串,询问每个字符串最多由多少个相同的子串重复连接而成.如:ababab,最多由3个ab连接而成. 输入输出格式 输入格式 若干行,每行一个字符串. 当读入到“.”时结束程序. 输出格式 若干行,为对应的答案. 输入输出样例 输入样例 abcd aaaa ababab . 输出样例 1 4 3 题解 这道题可以用字符串hash或kmp来做. 主要就是要将这道题转换成求最长前缀满足同为后缀. 假设在s[1...n]中,s[1...i]为前缀且s[n-i+…
Power Strings Description - Given two strings a and b we define ab to be their concatenation. For example, if a = "abc" and b = "def" then ab = "abcdef". If we think of concatenation as multiplication, exponentiation by a non…
题目大意 给定一个长为\(n\)的01串\(S\),每次你可以对一个串的三个连续位置做:\(011 \rightarrow 110\),\(110 \rightarrow 011\)的操作. 有\(q\)次询问,每次询问给出两个长度相等的子串,问是否能从一个串变到另一个串. 题解 首先,我们发现操作不改变\(1\)的个数.所以可以先用前缀和判断\(1\)的个数是否相等. 如果某个字符串不出现相邻的两个\(1\),那么容易得到你无法做任何有效的操作,就直接判断是否相等.这一步可以用hash或sa或…