新浪LCS,只过20%,想不明白为什么?
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
string str1;
string str2;
while(cin>>str1>>str2){
int n1=str1.size();
int n2=str2.size();
vector<vector<int> > dp(n1+1,vector<int>(n2+1,0));
for(int i=1;i<=n1;i++){
for(int j=1;j<=n2;j++){
if(str1[i-1]==str2[j-1]){
dp[i][j]=dp[i-1][j-1]+1;
}
else{
dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
}
}
}
cout<<dp[n1][n2]<<endl;
}
return 0;
}
新浪LCS,只过20%,想不明白为什么?#笔试题目##新浪#

