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 <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define INF 10000
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue const int MAXN = + ; int n,m; int dp[][];
int a[]; int main()
{
int i,j;
int t;
cin>>t;
while(t--)
{
cin>>n;
for(i=;i<=n;i++)
{
sf("%d",&a[i]);
}
for(int i = ;i<=n;i++)
{
for(j=i;j<=n;j++)
{
dp[i][j] = j-i+;
}
} for(int i = n-;i>=;i--)
{
for(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]);
}
}
}
pf("%d\n",dp[][n]); }
return ;
}
/*
2
4
1 2 1 2
7
1 2 1 1 3 2 1
*/
Light OJ 1422 - Halloween Costumes(区间DP 最少穿几件)的更多相关文章
- light oj 1422 Halloween Costumes (区间dp)
		题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ... 
- LightOJ - 1422 Halloween Costumes —— 区间DP
		题目链接:https://vjudge.net/problem/LightOJ-1422 1422 - Halloween Costumes PDF (English) Statistics F ... 
- dp之区间:Light oj 1422 Halloween Costumes
		http://lightoj.com/volume_showproblem.php?problem=1422 题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多 ... 
- LightOJ 1422  Halloween Costumes 区间dp
		题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新d ... 
- light oj 1422 - Halloween Costumes
		题意:告诉有n场晚会中需要穿的衣服,衣服是可以套在其他衣服外面的,也就是说如果顺序为 1 2 1,那么可以将2套在1外面,第三场晚会需要穿1的时候把2脱掉即可,这样就只需要穿两次衣服.题目是再告诉了顺 ... 
- 【LightOJ 1422】Halloween Costumes(区间DP)
		题 题意 告诉我们每天要穿第几号衣服,规定可以套好多衣服,所以每天可以套上一件新的该号衣服,也可以脱掉一直到该号衣服在最外面.求最少需要几件衣服. 分析 DP,dp[i][j]表示第i天到第j天不脱第 ... 
- Light OJ  1033 - Generating Palindromes(区间DP)
		题目大意: 给你一个字符串,问最少增加几个字符使得这个字符串变为回文串. ============================================================= ... 
- Light OJ 1031 - Easy Game(区间dp)
		题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031 题目大意:两个选手,轮流可以从数组的任意一端取值, 每次可以去任意个但仅 ... 
- Lightoj 题目1422 - Halloween Costumes(区间DP)
		1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ... 
随机推荐
- [ActionScript 3.0] 绘制扇形方法
			/** * 绘制扇形 * @param mc 承载扇形的对象 * @param x 圆心角x * @param y 圆心角y * @param r 半径 * @param angle 绘制角度 * @ ... 
- Event(补交作业)
			三种方法可以创建Eventhandler 1. 
- unix高级编程阅读
			一.进程: fork,exec,waitpid 1.子进程:复制进程的代码与堆栈状态,因此子进程将会从刚执行的指令fork位置继续往下执行. 2.父进程通过waitpid等待子进程完成 二.线程: 1 ... 
- jquery实现简易的计算器
			<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ... 
- 【Template】Miller Rabin
			#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #i ... 
- HNOI2018 退役记
			HNOI2018 退役记 \(day0\): 除了切水题以外没有什么很重要的事. \(day1\): 进考场发现前面是\(yyb\)?\(orzyyb\) 试题解压密码终于没有奇怪的字符了,一遍打对. ... 
- Shiro源码解析-登录篇
			本文以循序渐进的方式解析Shiro整个login过程的处理,读者可以边阅读本文边自己看代码来思考体会,如有问题,欢迎评论区探讨! 笔者shiro的demo源码路径:https://github.com ... 
- 正则基础之——NFA引擎匹配原理
			记录一下一篇很好的博文:https://blog.csdn.net/lxcnn/article/details/4304651 
- sencha touch overlay 里使用 list
			1 sencha touch 中 list 如果不设置一个固定高度或 flex : 1, list 的内容就不会显示出来. 主要是因为 list 是可滚动的,你不设置高度 ,list 的高度默认就是 ... 
- SSH框架学习步骤
			Hibernate 对象状态 关系映射 SQL语句 缓存抓取 struts action的分发配置 参数传递 文件上传 spring IOC AOP 
