标签:printf else char sequence 要求 一个 ace code adfs
题目链接:
http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=36
2 asdf adfsd 123abc abc123abc
3 6
#include<bits/stdc++.h> using namespace std; int f_max(int a,int b) { if(a>b) return a; else return b; } int main() { int t; scanf("%d",&t); getchar(); while(t--) { char a[1005]; char b[1005]; gets(a); gets(b); int l1=strlen(a); int l2=strlen(b); int dp[l1+1][l2+1]; memset(dp,0,sizeof(dp)); //dp[i][j]表示a0.....ai和b0....bj的LCS长度 for(int i=1; i<=l1; i++) { for(int j=1; j<=l2; j++) { if(a[i-1]==b[j-1])//以为i,j是从1开始的,所以i-1,j-1 { dp[i][j]=dp[i-1][j-1]+1; } else { dp[i][j]=f_max(dp[i-1][j],dp[i][j-1]); } } } printf("%d\n",dp[l1][l2]); } return 0; }
标签:printf else char sequence 要求 一个 ace code adfs
原文地址:https://www.cnblogs.com/yinbiao/p/8997637.html