最大公共子串 动态规划
#include <stdio.h>
#include <string.h>

#define N 256
int f(const char* s1, const char* s2)
{
int a[N][N];
int len1 = strlen(s1);
int len2 = strlen(s2);
int i,j;

memset(a,0,sizeof(int)*N*N);
int max = 0;
for(i=1; i<=len1; i++)
{
    for(j=1; j<=len2; j++)
	{
        if(s1[i-1]==s2[j-1]) 
		{
            a[i][j] = a[i-1][j-1]+1;  //填空
            if(a[i][j] > max) max = a[i][j];
        }
    }
}

return max;

}

int main()
{
printf("%d\n", f(“abcdkkk”, “baabcdadabc”));
return 0;
}

相关文章:

  • 2022-12-23
  • 2021-07-17
  • 2022-01-28
  • 2022-12-23
  • 2021-12-30
  • 2021-05-14
  • 2021-08-21
  • 2021-09-15
猜你喜欢
  • 2021-07-19
  • 2021-09-17
  • 2021-10-25
  • 2022-01-16
  • 2021-05-24
  • 2021-06-16
  • 2021-12-08
相关资源
相似解决方案