HDOJ 1159 Common Subsequence

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
static int m[1024][1024];
static int com_sub_seq(const char *pstr1,const char *pstr2)
{
	int len1=strlen(pstr1);
	int len2=strlen(pstr2);
	int i,j;
	for(i=1;i<=len1;i++){
		for(j=1;j<=len2;j++){
			if(pstr1[i-1]==pstr2[j-1])
				m[i][j]= m[i-1][j-1]+1;
			else
				m[i][j]= m[i-1][j] > m[i][j-1] ? m[i-1][j] : m[i][j-1];
		}
	}
	return m[len1][len2];
}

int main(int argc,char *argv[])
{
	char buf1[1024];
	char buf2[1024];
	while(scanf("%s%s",buf1,buf2)>0){
		printf("%d\n",com_sub_seq(buf1,buf2));
	}
	return 0;
}

 

你可能感兴趣的:(include)