Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

string
str1, str2;

int
ans[
1001][1001], l1, l2, maxi;

void
__init__()
{
    l1 
= str1.length();
    l2 
= str2.length();
    maxi
= 0;
    memset( ans, 
0sizeof ans );
}

void
__dp__()
{
    
forint i = 1; i <= l1; i++ )
        
forint j = 1; j <= l2; j++ )
            
if( str1[i - 1== str2[j - 1] )
            {
                ans[i][j] 
= ans[i - 1][j - 1+ 1;
                
if( maxi < ans[i][j] )
                    maxi 
= ans[i][j];
            }
            
else
            {
                
if( ans[i][j - 1> ans[i - 1][j] )
                    ans[i][j] 
= ans[i][j - 1];
                
else
                    ans[i][j] 
= ans[i - 1][j];
            }
}

void
__outp__()
{
    cout 
<< maxi << endl;
}

void
__read__()
{
    
while( cin >> str1 >> str2 )
    {
        __init__();
        __dp__();
        __outp__();
    }
}

int
main()
{
    __read__();

    
return 0;
}

posted on 2009-09-15 21:12 mad4alcohol 阅读(149) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理