设为首页 加入收藏

TOP

POJ - 1458 - Common Subsequence (LCS)
2015-11-21 01:03:21 来源: 作者: 【 】 浏览:1
Tags:POJ 1458 Common Subsequence LCS

?

?

思路:LCS

?

AC代码:

?

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include
           #include 
           
             #include 
            
              #include 
             
               #define LL long long #define INF 0x7fffffff using namespace std; char s[205]; char t[205]; int dp[205][205]; int main() { while(scanf(%s %s, s + 1, t + 1) != EOF) { int ls = strlen(s + 1); int lt = strlen(t + 1); memset(dp, 0, sizeof(dp)); for(int i = 1; i <= ls; i ++) { for(int j = 1; j <= lt; j ++) { if(s[i] == t[j]) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = max(dp[i-1][j], dp[i][j-1]); } } } cout << dp[ls][lt] << endl; } return 0; } 
             
            
           
         
        
       
      
     
    
   
  


?

?

?

?

?

?

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 2418 Hardwood Species(字典.. 下一篇Sicily 14257. Myvim Plugin

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: