1029 B exercises start all over again
KONO 题面 哒!
Problem Description
WX2004 as a non Emirates, playing what must use human wave tactics to heap dead opposite. That day he opened the GFL, found himself because too much food too was downgraded to a non-YM. He was very sorry for what I the fact that too much food, so ready to turn over a new leaf. He counted his former human form and human form have now have, and they got the two strings s, t and then press metaphysical method of indescribable sort of star with the letter number. He is now the core formation play 8 ,. Because he dishes nor, he had to have his own human form (that is, t sequence) in order to separate k groups and Jagged wheel war. But before he is demoted too miss team, a team was required that a string of k can be found in the original sequence and the same human form (i.e., s sequence). He has now pumping less due to Chen autistic, and ask you to help him calculate how many people they can plug into the ranks of shape.
( Note : No i.e. by star with letters a, b, c ...... ...... Since at this time instead of 1,2,3 GFL after several updates, it is not only six stars, 26. .)
( Title effect : selecting k disjoint nonempty continuous string from s, t, maintaining each substring s, t in the sequence of relative positions, so that each sub-string identical and opposing all determined and the maximum length of the substring. s given, only lowercase t)
input format
of the first row of three integers n, m, k, representing the string s, of length t, a selected sub-string number.
The second line of a string s.
The third line of a string t.Output format
line an integer representing the maximum value and the selected sub-string length.
Sample input
15. 4. 9
ababaaabbaaaabb
bbaababbb
sample output
8
Data range
\ (n, m ≤ 1000,
See that the original title of people are the devil's face
At first glance fixed return. Then I hit explode. Finally, I paid search, Wa0.
Go move ideas:
- Status: \ (F [i] [ j] [l] [s] \) represents s a sequence taken to No. i bit, t in the sequence accessible to the j-th bit, now take the Group l Figures, first i, j No. candidates not selected (0 must be selected, 1 optional is optional)
- State transition equation:
-
- \ (S [i] = t [j] \!): \ (F [i] [j] [l] [1] = max (f [i-1] [j] [l] [1], f [i] [j-1] [l] [1]) \) (may be optionally selected not able to open the new group, to assign a state to come)
-
- \ (S [i] = t [j] \): \ (f [i] [j] [l] [0] = f [i-1] [j-1] [l-1] [1] + 1 \) (can open a new group)
-
-
- If at this time: \ (s [i-1] = t [j-1] \): \ (f [i] [j] [l] [0] = max (f [i] [j] [l] [0], f [i-1] [j-1] [l] [0] +1) \) (the new groups do not open)
-
-
-
- After determining a condition, \ (f [i] [ j] [l] [1] = max (f [i] [j] [l] [0], max (f [i-1] [j] [l] [1], f [i] [j-1] [l] [1])) \) ( typically by transfer)
(it should be well understood ......)
- After determining a condition, \ (f [i] [ j] [l] [1] = max (f [i] [j] [l] [0], max (f [i-1] [j] [l] [1], f [i] [j-1] [l] [1])) \) ( typically by transfer)
-
KONO bill 码哒!
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int n,m,k;
char tmp[1010];
int f[1010][1010][11][2];
int a[1010],b[1010];
int main()
{
scanf("%d%d%d",&n,&m,&k);
int l,i,j;
scanf("%s",tmp);
for(i=1;i<=n;i++)a[i]=tmp[i-1]-'a';
scanf("%s",tmp);
for(i=1;i<=m;i++)b[i]=tmp[i-1]-'a';
for(l=1;l<=k;l++)
{
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i]==b[j]){
f[i][j][l][0]=f[i-1][j-1][l-1][1]+1;
if(a[i-1]==b[j-1]){
f[i][j][l][0]=max(f[i][j][l][0],f[i-1][j-1][l][0]+1);
}
f[i][j][l][1]=max(f[i][j][l][0],max(f[i-1][j][l][1],f[i][j-1][l][1]));
}
else f[i][j][l][1]=max(f[i-1][j][l][1],f[i][j-1][l][1]);
}
}
}
printf("%d\n",f[n][m][k][1]);
}
Xiagaitimian .jpg