题目链接:http://ac.jobdu.com/problem.php?pid=1042
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
//
// 1042 Coincidence.cpp
// Jobdu
//
// Created by PengFei_Zheng on 24/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#define MAX_SIZE 101 using namespace std; char a[MAX_SIZE];
char b[MAX_SIZE];
int dp[MAX_SIZE][MAX_SIZE]; int main(){
while(scanf("%s%s",a,b)!=EOF){
int lena = (int)strlen(a);
int lenb = (int)strlen(b);
for(int i = ; i <= lena ; i++){
dp[i][] = ;
}
for(int j = ; j <= lenb ; j++){
dp[][j] = ;
}
for(int i = ; i <= lena ; i++){
for(int j = ; j <= lenb ; j++){
if(a[i-]!=b[j-]){
dp[i][j] = max(dp[i-][j],dp[i][j-]);
}
else{
dp[i][j] = dp[i-][j-]+;
}
}
}
printf("%d\n",dp[lena][lenb]);
}
return ;
}
/**************************************************************
Problem: 1042
User: zpfbuaa
Language: C++
Result: Accepted
Time:0 ms
Memory:1560 kb
****************************************************************/