zoukankan      html  css  js  c++  java
  • LightOJ 1033 区间dp

    其实就是求最长回文序列的长度m,然后答案=n-m;

    /********************
    
    LightOJ 1033
    
    Author:Cdegree
    
    ********************/
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <cctype>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <map>
    #include <algorithm>
    #include <iostream>
    #include <string>
    #include <set>
    #define X first
    #define Y second
    #define sqr(x) (x)*(x)
    #pragma comment(linker,"/STACK:102400000,102400000")
    using namespace std;
    const double PI = acos(-1.0);
    map<int, int>::iterator it;
    typedef long long LL ;
    template<typename T> void checkmin(T &x, T y) {x = min(x, y);}
    template<typename T> void checkmax(T &x, T y) {x = max(x, y);}
    
    const int N = 105;
    int dp[N][N];
    
    char s[N];
    int main() {
        int T;
        scanf("%d", &T);
        for(int t = 1; t <= T; ++t) {
            scanf("%s", s);
            int n = strlen(s);
            for(int i = 0; i < n; ++i)dp[i][i] = 1;
            for(int l = 1; l < n; ++l) {
                for(int i = 0; i + l < n; ++i) {
                    if(s[i] == s[i+l]) {
                        dp[i][i+l] = 2;
                        if(i + 1 <= i + l - 1)dp[i][i+l] += dp[i+1][i+l-1];
                    }
                    else {
                        dp[i][i+l] = max(dp[i+1][i+l], dp[i][i+l-1]);
                    }
                }
            }
            printf("Case %d: %d
    ",t,n-dp[0][n-1]);
        }
        return 0;
    }
  • 相关阅读:
    Java基础语法与变量初步学习
    Java基本数据类型转换
    Java变量常量与基本数据类型
    Java进制转换
    Java 开发环境配置
    Java运算符
    STL—vector删除重复元素
    子窗口和父窗口重绘
    怎么判断文件是否被占用
    多线程的理解
  • 原文地址:https://www.cnblogs.com/cxw199204/p/3348733.html
Copyright © 2011-2022 走看看