zoukankan      html  css  js  c++  java
  • poj1159 【LCS】

    思路:
    滚动数组;
    贴一发挫code…

    #include <iostream>
    #include <cstdio>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    typedef __int64 LL;
    
    const int N=5e3+10;
    
    int dp[3][N];
    int k,n;
    char s[N];
    char s1[N];
    char s2[N];
    
    int main()
    {
        scanf("%d",&n);
        scanf("%s",s+1);
        strcpy(s1+1,s+1);
    //    strrev(s+1);      //poj也给CE了...
    //    strcpy(s2+1,s+1);
        for(int i=1;i<=n;i++)
            s2[i]=s[n-i+1];
        k=1;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
        {
            k=1-k;
            for(int j=1;j<=n;j++)
            {
                if(s1[i]==s2[j])
                    dp[k][j]=dp[1-k][j-1]+1;
                else
                    dp[k][j]=max(dp[k][j-1],dp[1-k][j]);
            }
        }
        printf("%d
    ",n-dp[k][n]);
    }
  • 相关阅读:
    设计模式——策略模式
    LeetCode
    平凡世界里的万千思绪
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934898.html
Copyright © 2011-2022 走看看