题目链接 给一个字符串, q个询问, 每次询问求出[l, r]里有多少个回文串. 区间dp, dp[l][r]表示[l, r]内有多少个回文串. dp[l][r] = dp[l+1][r]+dp[l][r-1]-dp[l+1][r-1]+flag[l][r], 如果是回文串flag[l][r]为1. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #incl…
You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also are q queries, each query is described by two integers li, ri (1 ≤ li ≤ ri ≤ |s|). The answer to the query is the number of substrings of string s…
题目大意 给定一个字符串s,q个查询,每次查询返回s[l-r]含有的回文子串个数(题目地址) 题解 和有一次多校的题目长得好相似,这个是回文子串个数,多校的是回文子序列个数 用dp[i][j]表示,s[i..j]含有的回文子串个数,则dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]+flag[i][j](如果s[i..j]是回文子串则flag[i][j]=1,否则为0) 代码: #include<iostream> #include<cstring&…
题目链接:http://codeforces.com/problemset/problem/245/H 题目大意:给你一个字符串s,对于每次查询,输入为一个数对(i,j),输出s[i..j]之间回文串的个数. 容斥原理: dp[i][j] = dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]; if( str[i]==str[j] 并且 str[i+1..j-1]是回文串 ) dp[i][j]++; 代码: #include <cstdio> #include <cs…
首先马拉车一遍(或者用hash),再做个前缀和处理出f[i][j]表示以j为右端点,左端点在[i,j]的回文串个数 然后设ans[i][j]是[i,j]之间的回文串个数,那就有ans[i][j]=ans[i][j-1]+f[i][j] #include<bits/stdc++.h> #define pa pair<int,int> #define CLR(a,x) memset(a,x,sizeof(a)) using namespace std; typedef long lon…
Queries for Number of Palindromes time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also ar…
Queries for Number of Palindromes Problem's Link:   http://codeforces.com/problemset/problem/245/H Mean: 给你一个字符串,然后q个询问:从i到j这段字符串中存在多少个回文串. analyse: dp[i][j]表示i~j这段的回文串数. 首先判断i~j是否为回文,是则dp[i][j]=1,否则dp[i][j]=0; 那么dp[i][j]=dp[i][j]+dp[i][j-1]+dp[i+1[j…
H. Queries for Number of Palindromes time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also…
H. Queries for Number of Palindromes time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output You've got a string s = s1s2... s|s| of length |s|, consisting of lowercase English letters. There also…
[CF245H]Queries for Number of Palindromes(回文树) 题面 洛谷 题解 回文树,很类似原来一道后缀自动机的题目 后缀自动机那道题 看到\(n\)的范围很小,但是\(Query\)很多 所以提前预处理出每一段\(l,r\)的答案 时间复杂度\(O(n^2+Q)\) #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #includ…