zoukankan      html  css  js  c++  java
  • LightOJ 1422 Halloween Costumes(记忆化搜索)

    题意:给你n天分别要穿的衣服,可以套着穿,但是一旦脱下来就不能再穿了,问这n天要准备几件衣服。
        
    =================================================================================
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef long long LL;
    const LL INF = 0xfffffff;
    const LL maxn = 200005;
    int a[105], dp[105][105];
    
    int DFS(int L,int R)
    {
        if(dp[L][R])
            return dp[L][R];
        if(L == R)
            return 1;
        if(L > R)
            return 0;
        dp[L][R] = DFS(L+1, R) + 1;
    
        for(int k=L+1; k<= R; k++)
        {
            if(a[L] == a[k])
            {
                dp[L][R] = min(dp[L][R], DFS(L,k-1) + DFS(k+1,R) );
            }
        }
        return dp[L][R];
    }
    
    int main()
    {
        int T, n, cas = 1;
        scanf("%d", &T);
    
        while(T--)
        {
            scanf("%d", &n);
            memset(dp, 0, sizeof(dp));
            for(int i=1; i<=n; i++)
                scanf("%d", &a[i]);
    
            printf("Case %d: %d
    ",cas++, DFS(1, n));
        }
        return 0;
    }
  • 相关阅读:
    CCF NOI1032 菱形
    CCF NOI1031 等腰三角形
    CCF NOI1030 角谷猜想
    CCF NOI1029 信息加密
    CCF NOI1028 判断互质
    CCF NOI1027 数字之和
    CCF NOI1026 表演打分
    CCF NOI1025 统计奖牌
    CCF NOI1024 因子个数
    CCF NOI1023 最大跨度
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4836288.html
Copyright © 2011-2022 走看看