zoukankan      html  css  js  c++  java
  • Light OJ 1422

    http://www.cnblogs.com/kuangbin/archive/2013/04/29/3051392.html

    http://www.cnblogs.com/ziyi--caolu/archive/2013/08/01/3229668.html

    http://www.cfanz.cn/index.php?c=article&a=read&id=172173

    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <cctype>
    #include <vector>
    #include <iterator>
    #include <set>
    #include <map>
    #include <sstream>
    using namespace std;
    
    #define mem(a,b) memset(a,b,sizeof(a))
    #define pf printf
    #define sf scanf
    #define spf sprintf
    #define pb push_back
    #define debug printf("!
    ")
    #define INF 10000
    #define MAX(a,b) a>b?a:b
    #define blank pf("
    ")
    #define LL long long
    #define ALL(x) x.begin(),x.end()
    #define INS(x) inserter(x,x.begin())
    #define pqueue priority_queue
    
    const int MAXN = 1000 + 5;
    
    int n,m;
    
    int dp[110][110];
    int a[110];
    
    int main()
    {
        int i,j;
        int t;
        cin>>t;
        while(t--)
        {
            cin>>n;
            for(i=1;i<=n;i++)
            {
                sf("%d",&a[i]);
            }
            for(int i = 1;i<=n;i++)
            {
                for(j=i;j<=n;j++)
                {
                    dp[i][j] = j-i+1;
                }
            }
    
            for(int i = n-1;i>=1;i--)
            {
                for(j=i+1;j<=n;j++)
                {
                    dp[i][j] = dp[i+1][j] + 1;
                    for(int k = i;k<=j;k++)
                    {
                        if(a[i]==a[k])
                            dp[i][j] = min(dp[i][j],dp[i+1][k-1]+dp[k][j]);
                    }
                }
            }
            pf("%d
    ",dp[1][n]);
    
        }
        return 0;
    }
    /*
    2
    4
    1 2 1 2
    7
    1 2 1 1 3 2 1
    */
  • 相关阅读:
    洛谷 P1231 教辅的组成
    BZOJ 2190: [SDOI2008]仪仗队
    Codeforces GYM 100741A . Queries
    COGS 1298. 通讯问题
    洛谷 P2604 [ZJOI2010]网络扩容
    codevs 1227 方格取数 2
    codevs 1004 四子连棋
    洛谷 P2319 [HNOI2006]超级英雄
    洛谷 P2153 [SDOI2009]晨跑
    插入排序
  • 原文地址:https://www.cnblogs.com/qlky/p/5454133.html
Copyright © 2011-2022 走看看