B - Halloween Costumes
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <vector> #define Faster ios::sync_with_stdio(false),cin.tie(0)
#define Read freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define Close fclose(stdin),fclose(stdout)
const int maxn = ;
using namespace std;
const int MOD = 1e9+;
typedef long long ll; int a[maxn];
int dp[maxn][maxn];
//dp[i][j],从区间i -> j 穿的最少的衣服数量 int main(){
Faster;
int t;
cin >> t;
int cnt = ;
while(t--){
cnt++;
int n;
cin >> n;
for(int i = ;i <= n;i++){
cin >> a[i];
}
//初始化,每件都穿上
for(int i = ;i <= n;i++){
for(int j = i;j <= n;j++){
dp[i][j] = j-i+;
}
}
for(int i = n-;i >= ;i--){
for(int j = i+;j <= n;j++){
dp[i][j] = dp[i+][j] + ;
for(int k = i;k <= j;k++){
if(a[i] == a[k]){
dp[i][j] = min(dp[i][j], dp[i+][k-] + dp[k][j]);
}
}
}
}
cout << "Case " << cnt << ": " << dp[][n] << endl;
}
return ;
}
B - Halloween Costumes的更多相关文章
- Lightoj 题目1422 - Halloween Costumes(区间DP)
1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- LightOj 1422 Halloween Costumes(区间DP)
B - Halloween Costumes Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- LightOJ - 1422 Halloween Costumes —— 区间DP
题目链接:https://vjudge.net/problem/LightOJ-1422 1422 - Halloween Costumes PDF (English) Statistics F ...
- LightOJ - 1422 Halloween Costumes (区间dp)
Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he i ...
- Halloween Costumes(区间DP)
Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning t ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- light oj 1422 Halloween Costumes (区间dp)
题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...
- 【LightOJ 1422】Halloween Costumes(区间DP)
题 题意 告诉我们每天要穿第几号衣服,规定可以套好多衣服,所以每天可以套上一件新的该号衣服,也可以脱掉一直到该号衣服在最外面.求最少需要几件衣服. 分析 DP,dp[i][j]表示第i天到第j天不脱第 ...
- LightOJ1422 Halloween Costumes(区间DP)
题目大概是依次有n场派对,每场派对都有需要穿某套衣服去参加,可以同时穿多套衣服,就是一套套着一套,如果脱了的话就不能再穿上那套了,问最少需要几套衣服去参加完所有派对. 区间DP: dp[i][j]第i ...
- LightOJ 1422 Halloween Costumes 区间dp
题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新d ...
随机推荐
- tornado安全应用之用户认证
在这个例子中,我们将只通过存储在安全cookie里的用户名标识一个人.当某人首次在某个浏览器(或cookie过期后)访问我们的页面时,我们展示一个登录表单页面.表单作为到LoginHandler路由的 ...
- for(String s:list)的运行
源码 List<String> list = new ArrayList<>(); for (String s:list){ } class文件 List<String& ...
- LVS集群中的IP负载均衡技术
LVS集群中的IP负载均衡技术 章文嵩 (wensong@linux-vs.org) 转自LVS官方参考资料 2002 年 4 月 本文在分析服务器集群实现虚拟网络服务的相关技术上,详细描述了LVS集 ...
- CSS中float与A标签的疑问
<stype> a{ text-decoration:none; float:left;} </stype> <div class="box1"> ...
- loj#2340. 「WC2018」州区划分
FWT&&FMT板子 #include<cstdio> #include<iostream> #include<cstring> #include& ...
- js里=、== 和===有什么区别?
说明:该文章是转载后进行修改完善的,望大家有收获. =是赋值运算符,==是关系运算符; ===是全等运算符. ”==”与”===”是不同的,一个是判断值是否相等,一个是判断值及类型是否完全相等.第一个 ...
- 【概念】SVG(1)
ok,我们讲讲svg 学习前提:懂HTML和基本的XML SVG简介: 1.SVG全称Scable Vector Graphic,可伸缩的矢量图 2.SVG用于定义针对于Web的基于矢量的图形 3.S ...
- 内部类访问外部类方法中的参数-使用final
public synchronized <T extends MetricsSource> T register(final String name, final String desc, ...
- 洛谷P4092树——并查集
题目:https://www.luogu.org/problemnew/show/P4092 利用并查集,倒序离线,那么从倒序来看被撤销标记的点就再也不会被标记,所以用并查集跳过: 莫名其妙的WA,调 ...
- POJ1226(strstr)
Substrings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13348 Accepted: 4722 Descr ...