link:http://poj.org/problem?id=1458
最基础的那种
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
int sad[][];char apple[],pear[];
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin );
#endif // ONLINE_JUDGE
// while (gets(apple)!=NULL && gets(pear)!=NULL)
while (~scanf("%s%s",apple,pear))
{
memset(sad,,sizeof(sad));
int lena=strlen(apple),lenp=strlen(pear);
for(int i=;i<lena;++i)
{
for(int j=;j<lenp;++j)
{
if(apple[i]==pear[j]) sad[i+][j+]=sad[i][j]+;
else sad[i+][j+]=max(sad[i][j+],sad[i+][j]);
}
}
printf("%d\n",sad[lena][lenp]);
} return ;
}
开始把sad数组类型写成char型了,样例竟然也会对。