In this paper, the longest master sequence solution for C + + dynamic programming is described. Share to everyone for your reference. The specific analysis is as follows:
Problem Description:
Find the length of the longest childe sequence in two strings.
Input:
Csblog
Belong
Output:
Max length = 4
Implementation code:
#include <stdio.h>
#include <string.h>
int arr[200][200];
/* Represents the length of the longest childe sequence of the front I and str2 of the str1 * *
int main ()
{
char str1[100],str2[100];
/* Input Data * *
scanf ("%s%s", str1,str2);
int len1 = strlen (str1);
int len2 = strlen (str2);
/* Initialize array *
/int i,j;
for (i = 0; I <= len1. ++i)
{for
(j = 0; J <= len2; ++j)
arr[i][j] = 0;
}
/* COMPUTE * *
for (i = 1; I <= len1 ++i)
{
for (j = 1; j <= len2; ++j)
{/
* characters are the same, then the longest childe sequence length plus 1 *
/if (str1[i-1] = = Str2[j-1])
{
arr[i][j] = arr[i-1][j-1] + 1;
}
else///The
current character is not the same, then take the last selected maximum as the current result/*
Arr[i][j]=arr[i][j-1]>arr[i-1][j]?arr[i][j-1]:arr[i-1][j ];
}
}
}
/* Output result
/printf ("max length =%d\n", Arr[len1][len2]);
return 0;
}
I hope this article will help you with the C + + program design.