CodeForces - 245H Queries for Number of Palindromes 题意:给定一个字符串,求区间[l,r]内有多少回文子串。 解:回文杀我。区间dp++ 首先这玩意不能像前缀和一样[l,r]=[1,r]-[1,l-1]。 那就直接设dp[i][j]为[i,j]中回文子串的数量。 考虑拿小的拼大的。如果两端不等, dp[i][j]=dp
intlen =strlen(s); memset(Is ,false,sizeof(Is)); for(inti = 0 ; i < len ; i++) { Is[i][i] =true; } for(intl = 1 ; l < len ; l++) { for(inti = 0 ; i < len && i + l < len ; i++) { intj = i + l; if(s[i] == s[j]) { if(l == 1) { Is[...
Queries for Number of Palindromes CodeForces - 245H(区间DP,判断回文串) Queries for Number of Palindromes 题目链接:CodeForces - 245H 题意:给出一个字符串,q个询问,每次询问区间[l, r]中的包含的回文串的数量; 思路:令dp[i][j]表示区间[i, j]中回文串的个数, p[i][j]表示区间[i, j]是否...
memset ( isPar , 0 , sizeof ( isPar ) ); for ( int i = 0 ; i < n ; i++ ) dp[i][i] = 1; for ( int i = 0 ; i < n ; i++ ) for ( int j = 0 ; j+i < n ; j++ ) { int k = j+i; isPar[j][k] = check ( j , k ); } for ( int i = 1 ; ...
Codeforces 245H Queries for Number of Palindromes 回文自动机 给出n≤1e3n\leq1e3n≤1e3的字符串,每次区间查询[l,r][l,r][l,r]有多少个回文串。 因为n≤1e3n\leq1e3n≤1e3,直接对每个左端点重新建回文树,然后暴力右端点更新区间答案。询问O(1)O(1)O(1)回答即可。......
【CodeForces - 245H 】Queries for Number of Palindromes (带容斥的区间dp),题干:You'vegotastring s = s1s2... s|s| oflength |s|,consistingoflowercaseEnglishletters.Thereal
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int q; char s[5050]; bool f[5000][5000]; int g[5000][5000]; int main() { scanf("%s", s); int n = strlen(s); for(int i = 0; i < n; i++) { for(int j = i; j >= 0; j--) { if...
7 years ago,#^| 0 constraints on the string length in this question is 100000, so O(|S|2) won't work. →Reply Laiu 7 years ago,#| -15 Hint:The number of distinct palindromes in a string of length n can't exceed n →Reply...
题目链接:http://codeforces.com/problemset/problem/245/H 题意: 给你一个字符串s。 然后有t个询问,每个询问给出x,y,问你区间[x,y]中的回文子串的个数。 题解: 表示状态: dp[x][y] = numbers 表示区间[x,y]中的回文子串个数
{for(inti=N;i>=1;i--)for(intj=i;j<=N;j++){if(j-i==0) ok[i][j]=1,dp[i][j]=1;elseif(j-i==1) dp[i][j]=ok[i][j]=dp[i][i]+dp[j][j]+(c[i]==c[j]?1:0);else{ ok[i][j]=ok[i+1][j-1]&(c[i]==c[j]); ...