Light oj 1422 - Halloween Costumes

题目:http://lightoj.com/volume_showproblem.php?problem=1422

#include <cstdio>
#include <iostream>

using namespace std; 

int c[105];
int dp[105][105];

int main ()
{
    int T, N;
    scanf("%d", &T);
    for(int kase=1; kase<=T; kase++) {
        scanf("%d", &N);
        for(int i=0; i<N; i++) {
            scanf("%d", &c[i]);
            dp[i][i] = 1;
        }
        for(int step=1; step<N; step++) {
            for(int i=0; i+step<N; i++) {
                int j = i+step;
                dp[i][j] = dp[i][j-1]+1;
                for(int k=i; k<j; k++) {
                    if(c[j]==c[k]) {
                        dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j-1]);
                    }
                }
            }
        }
        printf("Case %d: %d\n", kase, dp[0][N-1]);
    }
    return 0;
}
时间: 2024-12-30 03:51:12

Light oj 1422 - Halloween Costumes的相关文章

light oj 1422 - Halloween Costumes (区间dp)

1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Ha

Light OJ 1422 Halloween Costumes 区间DP基础题

Halloween Costumes 题目链接: http://lightoj.com/volume_showproblem.php?problem=1422 题意: Gappu想要去参加一些party,他去每个party都要把特定编号的服装穿在外边,他可以穿上或者脱掉服装(脱掉的服装不能再穿一次,但是可以穿一件相同编号新的服装,最近穿的服装会套在之前穿的服装的外边),问Gappu最少需要准备多少套服装. 题解: 设dp[i][j]为区间 i 到 j (设len为区间长度,j=i+len)内最少

Light OJ 1422 - Halloween Costumes(区间DP 最少穿几件)

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

Lightoj 题目1422 - Halloween Costumes(区间DP)

1422 - Halloween Costumes   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's

LightOJ 1422 Halloween Costumes (区间dp 好题)

1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, nextweekend is Halloween, and he is planning to attend as many parties as he can.Since it's Hall

LightOJ - 1422 Halloween Costumes (区间DP)

Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Halloween, these parties are all costume parties, Gappu always selects his costumes in such

LightOJ 1422 Halloween Costumes 区间dp

题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新dp[i][j]时有两种情况 考虑第i天穿的衣服 1:第i天穿的衣服在之后不再穿了 那么 dp[i][j]=dp[i+1][j]+1; 2:第i天穿的衣服与i+1到j的某一天共用,那么dp[i][j]=min(dp[i][j],dp[i+1][k-1],dp[k][j]),前提是第i天和第k天需要的礼

LightOJ 1422 Halloween Costumes 【区间DP】

题目链接:http://lightoj.com/volume_showproblem.php?problem=1422 解法:dp[i][j]=min(1+dp[i+1][j],dp[i+1][k-1]+dp[k][j]) 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include <str

LightOJ 1422 Halloween Costumes

dp[i]][j]=min(dp[i+1][j]+1,dp[i+1][k-1]+dp[k][j]) 表示第i天到j的最小数量.如果第i天的衣服只自己穿的话,不考虑后面的就是dp[i][j]=dp[i+1][j]+1.否则就是dp[i][j]=dp[i+1][k-1]+dp[k][j],其中第k天的衣服和第i天一样,这就是考虑第i天以后还有和它穿的衣服一样的情况 1 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c