light oj 1422 区间dp
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include <climits>
- #include <queue>
- #define ll long long
- using namespace std;
- int color[],n;
- int dp[][];
- int dfs(int l,int r)
- {
- if(r < l) return ;
- if(dp[l][r] != -)
- return dp[l][r];
- if(l == r)
- return dp[l][r] = ;
- dp[l][r] = r-l+;
- dp[l][r] = min(dfs(l+,r)+,dp[l][r]); //新穿一件
- for(int i = l+; i <= r; i++)
- {
- if(color[l] == color[i])
- dp[l][r] = min(dp[l][r],dfs(l+,i-)+dfs(i,r)); //l == i 不用新穿
- }
- return dp[l][r];
- }
- void solve()
- {
- scanf("%d",&n);
- memset(dp,-,sizeof(dp));
- for(int i = ; i <= n; i++)
- scanf("%d",&color[i]);
- int ans = dfs(,n);
- printf("%d\n",ans);
- }
- int main(void)
- {
- int t,cnt = ;
- scanf("%d",&t);
- while(t--)
- {
- printf("Case %d: ",++cnt);
- solve();
- }
- return ;
- }
light oj 1422 区间dp的更多相关文章
- light oj 1422 Halloween Costumes (区间dp)
题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...
- hdu 5693 && LightOj 1422 区间DP
hdu 5693 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5693 等差数列当划分细了后只用比较2个或者3个数就可以了,因为大于3的数都可以由2和3 ...
- LightOJ 1422 (区间DP)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27130 题目大意:按顺序去参加舞会.每个舞会对衣服都有要求.可以 ...
- light oj 1422 - Halloween Costumes
题意:告诉有n场晚会中需要穿的衣服,衣服是可以套在其他衣服外面的,也就是说如果顺序为 1 2 1,那么可以将2套在1外面,第三场晚会需要穿1的时候把2脱掉即可,这样就只需要穿两次衣服.题目是再告诉了顺 ...
- dp之区间:Light oj 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多 ...
- Light OJ 1422 - Halloween Costumes(区间DP 最少穿几件)
http://www.cnblogs.com/kuangbin/archive/2013/04/29/3051392.html http://www.cnblogs.com/ziyi--caolu/a ...
- light oj 1205(数位DP)
题目描述: 求给定区间中的回文数有多少个? 首先明确一点,如果一个数是回文数,那么给这个数两边加上相同的数,那么这个数还是回文数. 根据这点就可以进行递推了,p[start][end]=9*p[sta ...
- Light oj 1030 概率DP
D - Discovering Gold Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768 ...
- light oj 1032(数位DP)
求一段区间中,每个十进制数所对应的二进制数中连续的1的个数之和. 设dp[i][0]代表长度为i的二进制数,首位为0,所含有的连续的1的个数之和. dp[i][1]代表长度为i的二进制数,首位为1,所 ...
随机推荐
- lucene入门-搜索方式
1 package com.home.utils; import java.util.ArrayList; import java.util.List; import org.apache.lucen ...
- OpenCV-Python Tutorials目录
版本 3.4.6 1 Introduction to OpenCV OpenCV介绍Learn how to setup OpenCV-Python on your computer! 2 Gui F ...
- asprise-ocr-api-sample 高价收破解版64 32位
asprise-ocr-api-sample验证码 高价收破解版64 32位 Reflector 8.5 打开自己的C#代码 完全100%的反编译了
- struts使用
下载文件 <action name="download" class="thirdIssueAction" method="getDownloa ...
- bc 进制间转换
我们通过bc的ibase和obase方法来进行进制转换 ibase是输入数字的进制,而obase就是输出数字的进制 两种方式进行转化 交互式的 ==注意:需要先设置obase== [root@dev ...
- 【JZOJ6389】小w学图论
description 小w这学期选了门图论课,他在学习点着色的知识.他现在得到了一张无向图,并希望在这张图上使用最多n种颜色给每个节点染色,使得任意一条边关联的两个节点颜色不同. 小w获得一张n个节 ...
- SpringBoot入门到出家
SpringBoot的Actuator监控 Actuator:对系统的监控 是SpringBoot提供的对应用系统监控的集成功能,可以对系统进行配置查看,相关功能统计等,在Spring Cloud中, ...
- 组合数学——cf991E
/* 如果有某一位,那么这一位必须存在 枚举所有情况,计算每种情况时0额外另算 */ #include<bits/stdc++.h> using namespace std; #defin ...
- 解决eclipse启动时出现“failed to load the jni shared library”
如何解决启动eclipse出现failed to load the jni shared library的问题 问题描述:启动eclipse时,出现以下弹出框 此时,即表示eclispe和jdk位数不 ...
- springboot下自定义配置文件,并在项目里读取的方法
首先 pom文件引入springboot文件处理器 <dependency> <groupId>org.springframework.boot</groupId> ...