ProgramAlgTrain/20240915/1808/1808.cpp

43 lines
984 B
C++
Raw Normal View History

2024-09-15 09:35:54 +00:00
//http://noi.openjudge.cn/ch0206/1808
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
const int MAX_LEN = 200+5;
std::string s1,s2;
int dp[MAX_LEN][MAX_LEN];
template<typename T>
T max(const T t1,const T t2,const T t3){
return std::max(t1,std::max(t2,t3));
}
template<typename ...Args>
void print(const Args&...args){
std::stringstream ss;
((ss<<args),...);
std::cout<<ss.str();
return;
}
int main(){
while (std::cin>>s1>>s2) {
for(int i=1;i<=s1.length();i++){
for(int j=1;j<=s2.length();j++){
if(s1[i-1]==s2[j-1]){
dp[i][j] = dp[i-1][j-1] + 1;
}else{
dp[i][j] = max(dp[i][j-1], dp[i-1][j], dp[i-1][j-1]);
}
}
}
// std::cout<<dp[s1.length()][s2.length()]<<"\n";
print(dp[s1.length()][s2.length()],"\n");
}
}
/*
abcfbc abfcab
programming contest
abcd mnp
*/