Palindrome Bo (预处理 + 区间DP)】的更多相关文章

先进行离散化,然后再预处理出所有位置的下一个元素,做好这一步对时间的优化非常重要. 剩下的就是一般的DP了.区间DP #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; ll dp[maxn][maxn], f[maxn][maxn], a[maxn]; int nex[maxn][maxn], pre[maxn][maxn]; pair<ll, int>discre[maxn]; int m…
问题问的是最少可以把一个字符串分成几段,使每段都是回文串. 一开始想直接区间DP,dp[i][j]表示子串[i,j]的答案,不过字符串长度1000,100W个状态,一个状态从多个状态转移来的,转移的时候要枚举,这样时间复杂度是不可行的. 然后我就想降维度了,只能线性DP,dp[i]表示子串[0,i]的答案.这样可以从i-1转移到i,str[i]单独作一段或者str[i]能和前面的组成回文串,方程如下: dp[i]=min(dp[i-1]+1,dp[j-1]+1) (子串[j,i]是回文串) 现在…
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/Others) Total Submission(s): 2836 Accepted Submission(s): 1160 Problem Description In mathematics, a subsequence is a sequence that can be derived from a…
题目大意: 给你一个字符串,问这个字符串最少有多少个回文串. 区间DP直接搞     #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> using namespace std; typede…
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence <A, B, D> is a subsequence of <A, B, C, D, E, F>. (…
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/Others)Total Submission(s): 558    Accepted Submission(s): 203 Problem Description In mathematics, a subsequence is a sequence that can be derived fro…
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/Others) Total Submission(s): 2595    Accepted Submission(s): 1039 Problem Description In mathematics, a subsequence is a sequence that can be derived…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include <bits/stdc++.h> using namespace std; ; int dp[N][N], inf = 1e9; char str[N]; bool judge(int l, int r) { , j = r - ; i < j; ++i, --j) { if(str[i] !…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意:给你一个序列,问你该序列中有多少个回文串子序列,可以不连续. 思路:dp[i][j]表示序列i到j中具有的回文串序列数. 当s[i]==s[j], dp[i][j]=dp[i+1][j]+dp[i][j-1]+1 否则 dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]: #include <iostream> #include <cstdio…
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/Others)Total Submission(s): 4513    Accepted Submission(s): 1935 Problem Description In mathematics, a subsequence is a sequence that can be derived f…