LightOJ 1422 Halloween Costumes
dp[i]][j]=min(dp[i+1][j]+1,dp[i+1][k-1]+dp[k][j])
表示第i天到j的最小数量。如果第i天的衣服只自己穿的话,不考虑后面的就是dp[i][j]=dp[i+1][j]+1.否则就是dp[i][j]=dp[i+1][k-1]+dp[k][j],其中第k天的衣服和第i天一样,这就是考虑第i天以后还有和它穿的衣服一样的情况
//#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<algorithm>
#include<vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int Inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// } int a[];
int dp[][]; int main(){
int t;
int cas=;
scanf("%d",&t);
while(t--){
clc(dp,);
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]); for(int i=;i<=n;i++)
for(int j=i;j<=n;j++){
dp[i][j]=i-j+;
}
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[k]==a[i])
dp[i][j]=min(dp[i][j],dp[i+][k-]+dp[k][j]);
}
}
}
printf("Case %d: %d\n",cas++,dp[][n]);
}
return ;
}
LightOJ 1422 Halloween Costumes的更多相关文章
- LightOJ - 1422 Halloween Costumes —— 区间DP
题目链接:https://vjudge.net/problem/LightOJ-1422 1422 - Halloween Costumes PDF (English) Statistics F ...
- LightOj 1422 Halloween Costumes(区间DP)
B - Halloween Costumes Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- LightOJ 1422 Halloween Costumes 区间dp
题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新d ...
- LightOJ - 1422 Halloween Costumes (区间dp)
Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he i ...
- LightOJ 1422 Halloween Costumes(记忆化搜索)
题意:给你n天分别要穿的衣服,可以套着穿,但是一旦脱下来就不能再穿了,问这n天要准备几件衣服. =============================================== ...
- LightOJ 1422 Halloween Costumes (区间DP,经典)
题意: 有个人要去参加万圣节趴,但是每到一个趴都要换上特定的服装,给定一个序列表示此人要穿的衣服编号(有先后顺序的),他可以套很多件衣服在身上,但此人不喜欢再穿那些脱下的衣服(即脱下后就必须换新的), ...
- LightOJ 1422 Halloween Costumes 【 区间dp 】
区间dp的第一题----- 看题解看了好多~~终于看懂了---55555 dp[i][j] 表示第i天到第j天至少需要多少件衣服 那么第i件衣服只被第i天占用的话, dp[i][j] = dp[i+1 ...
- Lightoj 题目1422 - Halloween Costumes(区间DP)
1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
随机推荐
- What are the advantages of logistic regression over decision trees?FAQ
What are the advantages of logistic regression over decision trees?FAQ The answer to "Should I ...
- Bypass Preventing CSRF
CSRF在过去的n年(n>2)一直都火,在bh/defcon/owasp等会议上多次探讨CSRF的攻防[具体你可以看看以往的那些pp].前 段时间PLAYHACK.net上发表了一个总结性的pp ...
- 免费素材:25套免费的 Web UI 设计的界面元素(转)
Web 元素是任何网站相关项目都需要的,质量和良好设计的元素对于设计师来说就像宝贝一样.如果您正在为您的网站,博客,Web 应用程序或移动应用程序寻找完美设计的网页元素,那么下面这个列表会是你需要的. ...
- Firefly——dbentrust 示例DEMO (源码+教程)
原地址:http://www.9miao.com/question-15-54002.html Firefly——dbentrust示例说明一.数据库准备本篇示例演示的是firefly与MySQL和m ...
- 如何提高多线程程序的cpu利用率
正如大家所知道的那样,多核多cpu越来越普遍了,而且编写多线程程序也是件很简单的事情.在Windows下面,调用CreateThread函数一次就能够以你想要的函数地址新建一个子线程运行.然后,事情确 ...
- js jquery学习
1.js api http://api.vfreesoft.com/ 2.26个jquery小技巧 http://www.cnblogs.com/shouce/p/5084565.html 3. ...
- 【转】wireshark过滤规则
WireShark过滤语法 1.过滤IP,如来源IP或者目标IP等于某个IP 例子:ip.src eq 192.168.1.107 or ip.dst eq 192.168.1.107或者ip.add ...
- 191. Number of 1 Bits
题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also ...
- knowledge about apache
http://wenku.baidu.com/link?url=6O51BQJdtFRFWDGszKfN3aK7IY92QTCpuc7miBhRLazXvxL5gXb18B_TqIdi3EruX1o_ ...
- Invoke BeginInvoke
http://www.codeproject.com/Articles/10311/What-s-up-with-BeginInvoke http://www.codeproject.com/Arti ...