zoukankan      html  css  js  c++  java
  • hdu1159Common Subsequence

    Common Subsequence

    dp之最长公共子序列

    // File Name: hdu1159.cpp
    // Author: rudolf
    // Created Time: 2013年04月25日 星期四 12时12分33秒
    
    #include<vector>
    #include<list>
    #include<map>
    #include<set>
    #include<deque>
    #include<stack>
    #include<bitset>
    #include<algorithm>
    #include<functional>
    #include<numeric>
    #include<utility>
    #include<sstream>
    #include<iostream>
    #include<iomanip>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<ctime>
    #include<string>
    using namespace std;
    const int maxn=1005;
    int dp[maxn][maxn];
    int main()
    {
    	int len1,len2;
    	string str1,str2;
    	while(cin>>str1>>str2)
    	{
    		memset(dp,0,sizeof(dp));
    		for(int i=0;i<str1.length();i++)
    			for(int j=0;j<str2.length();j++)
    			{
    				if(str1[i]==str2[j])
    					dp[i+1][j+1]=dp[i][j]+1;
    				else
    					dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
    			}
    		cout<<dp[str1.length()][str2.length()]<<endl;
    
    	}
    return 0;
    }	


  • 相关阅读:
    第二章初识MySQL
    第一章 数据库
    Java&SQL7
    Java&SQL
    Java&SQL6
    Java&SQL5
    Java&SQL4
    Java&SQL3
    Java&SQL2
    博客地址已搬迁
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3042263.html
Copyright © 2011-2022 走看看