After giving a string, seeking to fill at least a few letters can form a palindrome string, we find find the most number of middle, as long as the rest of the asymmetric needs to fill (fill the left to the right, up the right side to the left so = len- substring same intermediate), so it is better to seek the middle of the substring, a reducing it.
string:len=s1.size();
char: len = strlen ();
Input from the beginning: scanf ( "% s", s1 + 1);
Counting from a subscript: int len = strlen (s1 + 1);
Since it is a palindrome string, about the same, you can find it upside down and it's the largest common subsequence directly.
But s1 [i] == s2 [j] when can then direct successor +1;
Such as
Adb3bdmzA
Azmdb3bdA
Most edge of A is not filled,
Longest common subsequence follows:
#include <bits/stdc++.h> using namespace std; int n,a[1000008],b[10000008],f[10008][10008]; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ if(a[i-1]==b[j-1]) f[i][j]=max(f[i][j],f[i-1][j-1]+1); else f[i][j]=max(f[i-1][j],f[i][j-1]); } int years = f [n] [n]; printf("%d",ans); return 0; }
The title and the code is as follows:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; char s1[1009],s2[1009]; int f[1009][1009],maxn; int main () { scanf("%s",s1+1); int len=strlen(s1+1); for(int i=1;i<=len;i++) s2[len-i+1]=s1[i]; for(int i=1;i<=len;i++){ for(int j=1;j<=len;j++){ if(s1[i]==s2[j]) f[i][j]=max(f[i][j],f[i-1][j-1]+1); else f[i][j]=max(f[i-1][j],f[i][j-1]); //maxn=max(maxn,f[i][j]); } } printf ( " % d " , alkylene- f [only] [only]); return 0; }
Make a yellow title fight I do not want to learn fast, state transition equation is still not listed.