• hdu1159Common Subsequence


    完全的一道水题,因为它来自书本,嘻嘻

    while(cin>>(list1+1)>>(list2+1)){
    int n1=strlen(list1+1);
    int n2=strlen(list2+1);这个是之前没有见过的一种输入法

    这种最长公共序列,倒是挺有必要掌握,人类基因图那一道题也是用这种方法的

    #include "iostream"
    #include "string.h"
    using namespace std;
    int dp[1000][1000];
    int max(int a,int b){return a>b?a:b;}
    int main(){
      char list1[1000],list2[1000];
      int i,j;
      while(cin>>(list1+1)>>(list2+1)){
        int n1=strlen(list1+1);
        int n2=strlen(list2+1);
        for(i=1;i<n2;i++)dp[0][i]=0;
        for(i=1;i<n1;i++)dp[i][0]=0;
        for(i=1;i<=n1;i++){
          for(j=1;j<=n2;j++){
            if(list1[i]==list2[j])dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          }
        }
        /*for(i=0;i<=strlen(list1);i++){
          for(j=0;j<=strlen(list2);j++)
            cout<<dp[i][j]<<' ';
          cout<<endl;
        }*/
    
        cout<<dp[n1][n2]<<endl;
      }
    }
  • 相关阅读:
    Postfix邮件
    RAID和LVM磁盘阵列
    CF1400G
    CF1400F
    2020 AC Saber夏季赛 游记
    APIO2018 题解
    2020北京中考游记
    初中数学几何推理大梳理
    CF1373F Network Coverage
    部编人教版初中历史书事件影响/意义汇总
  • 原文地址:https://www.cnblogs.com/dowson/p/3278647.html
Copyright © 2020-2023  润新知