hdu 1159 最有子结构
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,len1,len2;
char str[100],st[100];
int sum[100][100];
//freopen("e://2.txt","r",stdin);
while(scanf("%s %s",str,st)!=EOF)
{
memset(sum,0,sizeof(sum));
len1=strlen(str);
len2=strlen(st);
for(i=0;i<=len1;i++)
sum[i][0]=0;
for(i=0;i<=len2;i++)
sum[0][i]=0;
for(i=0;i<len1;i++)
for(j=0;j<len2;j++)
{
if(str[i]==st[j])
sum[i+1][j+1]=sum[i][j]+1;
else
{
if(sum[i][j+1]>sum[i+1][j])
sum[i+1][j+1]=sum[i][j+1];
else sum[i+1][j+1]=sum[i+1][j];
}
}
printf("%d\n",sum[len1][len2]);
}
return 0;
}
Just a little, maybe change the world