1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <climits>
  8. #include <queue>
  9. #define ll long long
  10.  
  11. using namespace std;
  12.  
  13. int color[],n;
  14. int dp[][];
  15.  
  16. int dfs(int l,int r)
  17. {
  18. if(r < l) return ;
  19. if(dp[l][r] != -)
  20. return dp[l][r];
  21. if(l == r)
  22. return dp[l][r] = ;
  23. dp[l][r] = r-l+;
  24.  
  25. dp[l][r] = min(dfs(l+,r)+,dp[l][r]); //新穿一件
  26.  
  27. for(int i = l+; i <= r; i++)
  28. {
  29. if(color[l] == color[i])
  30. dp[l][r] = min(dp[l][r],dfs(l+,i-)+dfs(i,r)); //l == i 不用新穿
  31. }
  32. return dp[l][r];
  33. }
  34.  
  35. void solve()
  36. {
  37. scanf("%d",&n);
  38. memset(dp,-,sizeof(dp));
  39. for(int i = ; i <= n; i++)
  40. scanf("%d",&color[i]);
  41. int ans = dfs(,n);
  42.  
  43. printf("%d\n",ans);
  44. }
  45.  
  46. int main(void)
  47. {
  48.  
  49. int t,cnt = ;
  50. scanf("%d",&t);
  51. while(t--)
  52. {
  53. printf("Case %d: ",++cnt);
  54. solve();
  55. }
  56. return ;
  57. }

light oj 1422 区间dp的更多相关文章

  1. light oj 1422 Halloween Costumes (区间dp)

    题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...

  2. hdu 5693 && LightOj 1422 区间DP

    hdu 5693 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5693 等差数列当划分细了后只用比较2个或者3个数就可以了,因为大于3的数都可以由2和3 ...

  3. LightOJ 1422 (区间DP)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27130 题目大意:按顺序去参加舞会.每个舞会对衣服都有要求.可以 ...

  4. light oj 1422 - Halloween Costumes

    题意:告诉有n场晚会中需要穿的衣服,衣服是可以套在其他衣服外面的,也就是说如果顺序为 1 2 1,那么可以将2套在1外面,第三场晚会需要穿1的时候把2脱掉即可,这样就只需要穿两次衣服.题目是再告诉了顺 ...

  5. dp之区间:Light oj 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多 ...

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

    http://www.cnblogs.com/kuangbin/archive/2013/04/29/3051392.html http://www.cnblogs.com/ziyi--caolu/a ...

  7. light oj 1205(数位DP)

    题目描述: 求给定区间中的回文数有多少个? 首先明确一点,如果一个数是回文数,那么给这个数两边加上相同的数,那么这个数还是回文数. 根据这点就可以进行递推了,p[start][end]=9*p[sta ...

  8. Light oj 1030 概率DP

    D - Discovering Gold Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768 ...

  9. light oj 1032(数位DP)

    求一段区间中,每个十进制数所对应的二进制数中连续的1的个数之和. 设dp[i][0]代表长度为i的二进制数,首位为0,所含有的连续的1的个数之和. dp[i][1]代表长度为i的二进制数,首位为1,所 ...

随机推荐

  1. lucene入门-搜索方式

    1 package com.home.utils; import java.util.ArrayList; import java.util.List; import org.apache.lucen ...

  2. OpenCV-Python Tutorials目录

    版本 3.4.6 1 Introduction to OpenCV OpenCV介绍Learn how to setup OpenCV-Python on your computer! 2 Gui F ...

  3. asprise-ocr-api-sample 高价收破解版64 32位

    asprise-ocr-api-sample验证码 高价收破解版64 32位 Reflector 8.5 打开自己的C#代码  完全100%的反编译了

  4. struts使用

    下载文件 <action name="download" class="thirdIssueAction" method="getDownloa ...

  5. bc 进制间转换

    我们通过bc的ibase和obase方法来进行进制转换 ibase是输入数字的进制,而obase就是输出数字的进制 两种方式进行转化 交互式的 ==注意:需要先设置obase== [root@dev ...

  6. 【JZOJ6389】小w学图论

    description 小w这学期选了门图论课,他在学习点着色的知识.他现在得到了一张无向图,并希望在这张图上使用最多n种颜色给每个节点染色,使得任意一条边关联的两个节点颜色不同. 小w获得一张n个节 ...

  7. SpringBoot入门到出家

    SpringBoot的Actuator监控 Actuator:对系统的监控 是SpringBoot提供的对应用系统监控的集成功能,可以对系统进行配置查看,相关功能统计等,在Spring Cloud中, ...

  8. 组合数学——cf991E

    /* 如果有某一位,那么这一位必须存在 枚举所有情况,计算每种情况时0额外另算 */ #include<bits/stdc++.h> using namespace std; #defin ...

  9. 解决eclipse启动时出现“failed to load the jni shared library”

    如何解决启动eclipse出现failed to load the jni shared library的问题 问题描述:启动eclipse时,出现以下弹出框 此时,即表示eclispe和jdk位数不 ...

  10. springboot下自定义配置文件,并在项目里读取的方法

    首先 pom文件引入springboot文件处理器 <dependency> <groupId>org.springframework.boot</groupId> ...