zoukankan      html  css  js  c++  java
  • poj 3280 Cheapest Palindrome

    题目链接http://poj.org/problem?id=3280

    题目分类:动态规划

    代码

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    
    using namespace std;
    
    int dp[2002][2002];
    
    int main()
    {
        int n, m;
        scanf("%d %d", &n, &m);
        char s[2002];
        cin>>s;
        int cost[200];
        int a, b;
        char c;
        for(int i=1;i<=n;i++)
        {
            cin>>c>>a>>b;
            cost[c] = a > b ? b : a;   // 插入a和删除a其实是等价,只需要选择出来一个较小的即可
        }
        for(int i=m-1;i>=0;i--)      //从后面往前
        {
            for(int j=i+1;j<m;j++)
            {
                if(s[i]==s[j])
                    dp[i][j] = dp[i+1][j-1];
                else
                    dp[i][j] = min(dp[i+1][j]+cost[s[i]], dp[i][j-1]+cost[s[j]]);
            }
        }
        cout<<dp[0][m-1]<<endl;
        return 0;
    }
    anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
  • 相关阅读:
    python—打开图像文件报错
    CTFshow萌新赛-萌新福利
    微信小程序bug
    微信小程序
    架构
    命令行
    MyBatis
    avalon
    并发测试工具
    less
  • 原文地址:https://www.cnblogs.com/gaoss/p/4934618.html
Copyright © 2011-2022 走看看