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

思路:区间DP,对于区间【i,j】,如果a[i]在[i+1,j]中未出现,dp[i][j] = dp[i+1][j]+1,否则a[i]应考虑是否被重复利用,若重复利用那么并不需要再一次穿上a[i],所以dp[i][j] = min(dp[i][j],dp[i][k-1],dp[k+1][j])。

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <queue>
  7. #include <algorithm>
  8. #define MAXSIZE 1005
  9. #define LL long long
  10. #define INF 0x3f3f3f
  11. #define mod 10056
  12.  
  13. using namespace std;
  14.  
  15. int dp[MAXSIZE][MAXSIZE],a[MAXSIZE];
  16.  
  17. int Solve(int n)
  18. {
  19. for(int i=;i<MAXSIZE;i++)
  20. {
  21. for(int j=i;j<MAXSIZE;j++)
  22. {
  23. dp[i][j] = j-i+;
  24. }
  25. }
  26.  
  27. for(int i=n;i>=;i--)
  28. {
  29. for(int j=i+;j<=n;j++)
  30. {
  31. dp[i][j] = dp[i+][j] + ;
  32. for(int k=i+;k<=j;k++)
  33. {
  34. if(a[k] == a[i])
  35. {
  36. dp[i][j] = min(dp[i][k-]+dp[k+][j],dp[i][j]);
  37. }
  38. }
  39. }
  40. }
  41. return dp[][n];
  42. }
  43.  
  44. int main()
  45. {
  46. int T,n,cns=;
  47. scanf("%d",&T);
  48. while(T--)
  49. {
  50. scanf("%d",&n);
  51. for(int i=;i<=n;i++)
  52. scanf("%d",&a[i]);
  53. int ans = Solve(n);
  54. printf("Case %d: %d\n",cns++,ans);
  55. }
  56. return ;
  57. }

light oj 1422 - Halloween Costumes的更多相关文章

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

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

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

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

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

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

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

    1422 - Halloween Costumes   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  5. LightOJ - 1422 Halloween Costumes —— 区间DP

    题目链接:https://vjudge.net/problem/LightOJ-1422 1422 - Halloween Costumes    PDF (English) Statistics F ...

  6. LightOj 1422 Halloween Costumes(区间DP)

    B - Halloween Costumes Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...

  7. LightOJ - 1422 Halloween Costumes (区间dp)

    Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he i ...

  8. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  9. LightOJ 1422 Halloween Costumes 区间dp

    题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新d ...

随机推荐

  1. (BFS) leetcode 690. Employee Importance

    690. Employee Importance Easy 377369FavoriteShare You are given a data structure of employee informa ...

  2. RJ45连接器

    http://www.huilyn.com/path315.html      HBJ-6308ANLF http://www.hanrun.com/en/           HR971169C h ...

  3. 洛谷P1119 灾后重建 Floyd + 离线

    https://www.luogu.org/problemnew/show/P1119 真是有故事的一题呢 半年前在宁夏做过一道类似的题,当时因为我的愚昧痛失了金牌. 要是现在去肯定稳稳的过,真是生不 ...

  4. 神经网络4_BP神经网络

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...

  5. Ubuntu编译Protobuf(Base tensorflow-12)报错

    报错1: dogepool@ubuntu-server:~/dogecoin$ ./autogen.sh./autogen.sh: 50: ./autogen.sh: autoreconf: not ...

  6. Hbase学习01

    1.1  快速介绍 1.1.1 快速入门,单节点Hbase 本小节介绍单节点独立HBase的设置. 独立实例包含所有HBase守护进程 - Master,RegionServers和ZooKeeper ...

  7. 【.net】The source was not found, but some or all event logs could not be searched

    1.案发现场: 注册服务的时候 2.解决方案: 用管理员身份运行CMD,再注册服务: I had to run Command Prompt with Administrator Rights.

  8. windows 中查找占用某个端口的进程并杀死的命令

    如图所示

  9. springMVC中a标签传递多个参数到后台的应用

    1.js页面:返回json填充HTML部分代码 <a class='byCard' href="+path+"/static/toCardView/"+ data. ...

  10. golang命令行参数

    os.Args获取命令行参数 os.Args是一个srting的切片,用来存储所有的命令行参数 package main import ( "fmt" "os" ...