Metal Steak

Hard to eat

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

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
ans[
201][201], l1, l2;

string
str1, str2, strr[
201][201];

void
__read__()
{
    cin 
>> str1 >> str2;
}

void
__init__()
{
    
forint i = 0; i <= 200; i++ )
        
forint j = 0; j <= 200; j++ )
            strr[i][j] 
= "";
    l1 
= str1.length();
    l2 
= str2.length();
    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;
                strr[i][j] 
=  strr[i - 1][j - 1+ str1[i - 1];
            }
            
else
            {
                
if( ans[i - 1][j] > ans[i][j - 1] )
                {
                    ans[i][j] 
= ans[i - 1][j];
                    strr[i][j] 
= strr[i - 1][j];
                }
                
else
                {
                    ans[i][j] 
= ans[i][j - 1];
                    strr[i][j] 
= strr[i][j - 1];
                }
            }
}

void
__outp__()
{
    cout 
<< ans[l1][l2] << endl << strr[l1][l2] << endl;
}

int
main()
{
    __read__();
    __init__();
    __dp__();
    __outp__();

    
return 0;
}

posted on 2009-09-15 20:55 mad4alcohol 阅读(44) 评论(0)  编辑 收藏 引用

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