心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
DP,最长不下降子序列。
Here is my code:
#include<iostream>
#include
<string>
#include
<string.h>
#define maxn 307
using namespace std;

string rkey,s;

long f(char ch)
{
    
for(long i=0;i<26;i++)
        
if(rkey.at(i)==ch)
            
return i;
    
return 0;
}

int main()
{
    cin
>>rkey;
    
while(cin>>s)
    {
        
long len=s.length(),ans,r[maxn],d[maxn];
        
for(long i=1;i<=len;i++)
            r[i]
=f(s.at(i-1));
        
for(long i=1;i<=len;i++)
            d[i]
=1;
        
for(long i=1;i<=len;i++)
            
for(long j=1;j<i;j++)
                
if(r[j]<=r[i]&&d[j]+1>d[i])
                    d[i]
=d[j]+1;
        ans
=0;
        
for(long i=1;i<=len;i++)
            
if(ans<d[i])
                ans
=d[i];
        cout
<<ans;
    }
    cout
<<endl;
return 0;
}
posted on 2010-10-22 01:14 lee1r 阅读(382) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:动态规划

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理