我做动态规划还是少的
只会做那些显而易见的动态规划题(这题是看了给出来的解题思路做的)
以后可能就会做与这类似的了
代码如下:
#include<stdio.h>
#include<string.h>
int get_min(int a, int b, int c);
int min_l[301][301];
char DNA_a[301], DNA_b[301];
int len_a, len_b;int main(void)
{scanf("%s %s", DNA_a, DNA_b);len_a = (int)strlen(DNA_a), len_b = (int)strlen(DNA_b);for(int i = 0; i <= len_a; i++)min_l[i][0] = i;for(int i = 0; i <= len_b; i++)min_l[0][i] = i;for(int i = 1; i <= len_a; i++)for(int j = 1; j <= len_b; j++)if(DNA_a[i - 1] == DNA_b[j - 1])min_l[i][j] = min_l[i - 1][j - 1];elsemin_l[i][j] = get_min(min_l[i - 1][j] + 1, min_l[i][j - 1] + 1, min_l[i - 1][j - 1] + 1);printf("%d ", min_l[len_a][len_b]);if(min_l[len_a][len_b] <= ((len_a < len_b) ? len_a : len_b) / 2)printf("matched");elseprintf("unmatched");return 0;
}
int get_min(int a, int b, int c)
{a = (a < b) ? a : b;return (a < c) ? a : c;
}