CSU-ACM2017暑假训练9-区间DP C
来源:互联网 发布:汉奇中走丝编程视频 编辑:程序博客网 时间:2024/05/19 14:53
C - Halloween Costumes
Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Halloween, these parties are all costume parties, Gappu always selects his costumes in such a way that it blends with his friends, that is, when he is attending the party, arranged by his comic-book-fan friends, he will go with the costume of Superman, but when the party is arranged contest-buddies, he would go with the costume of 'Chinese Postman'.Since he is going to attend a number of parties on the Halloween night, and wear costumes accordingly, he will be changing his costumes a number of times. So, to make things a little easier, he may put on costumes one over another (that is he may wear the uniform for the postman, over the superman costume). Before each party he can take off some of the costumes, or wear a new one. That is, if he is wearing the Postman uniform over the Superman costume, and wants to go to a party in Superman costume, he can take off the Postman uniform, or he can wear a new Superman uniform. But, keep in mind that, Gappu doesn't like to wear dresses without cleaning them first, so, after taking off the Postman uniform, he cannot use that again in the Halloween night, if he needs the Postman costume again, he will have to use a new one. He can take off any number of costumes, and if he takes off k of the costumes, that will be the last k ones (e.g. if he wears costume A before costume B, to take off A, first he has to remove B).Given the parties and the costumes, find the minimum number of costumes Gappu will need in the Halloween night.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.Each case starts with a line containing an integer N (1 ≤ N ≤ 100) denoting the number of parties. Next line contains N integers, where the ith integer ci (1 ≤ ci ≤ 100) denotes the costume he will be wearing in party i. He will attend party 1 first, then party 2, and so on.
Output
For each case, print the case number and the minimum number of required costumes.
Sample Input
241 2 1 271 2 1 1 3 2 1
Sample Output
Case 1: 3Case 2: 4
主角尬噗可以在参加完第一场聚会后,通过穿上一另件衣服,参加另一聚会,再脱下衣服的方法参加与第一场聚会dress code相同的第三场聚会,从而重复利用了第一件衣服。据此,我们可以考虑他在第
先假定他需要穿新装,那么第
状态转移方程:
#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>#include <queue>using namespace std;int sample[104], dp[104][104];int main(){#ifdef TESTfreopen("test.txt", "r", stdin);#endif // TEST int T, n, Cas = 1; cin >> T; while(T--){ memset(dp, 0, sizeof(dp)); cin >> n; for(int i = 0; i < n; i++){ cin >> sample[i]; dp[i][i] = 1; } for(int len = 1; len < n; len++){ for(int s = 0, e = len; e < n; s++, e++){ dp[s][e] = dp[s][e-1]+1; for(int k = s; k < e; k++){ if(sample[e] == sample[k]) dp[s][e] = min(dp[s][e], dp[s][k]+dp[k+1][e-1]); } } } printf("Case %d: %d\n", Cas++, dp[0][n-1]); } return 0;}
阅读全文
0 0
- CSU-ACM2017暑假训练9-区间DP C
- CSU-ACM2017暑假训练9-区间DP D
- CSU-ACM2017暑假训练9-区间DP E
- CSU-ACM2017暑假训练9-区间DP F
- CSU-ACM2017暑假训练9-区间DP G
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛1 C
- CSU-ACM2017暑假集训比赛2 C
- CSU-ACM2017暑假集训比赛7 C
- CSU-ACM2017暑期训练6-bfs C
- CSU-ACM2017暑假集训2-二分搜索 C
- CSU-ACM2017暑期训练1-Debug与STL C
- CSU-ACM2017暑期训练8-动态规划初步 C
- CSU-ACM2017暑期训练10-并查集&&HASH C
- CSU-ACM2017暑期训练16-树状数组 C
- 暑假训练-训练8 区间DP
- CSU-ACM2017暑假集训比赛1 B
- android listview仿ios 3dTouch效果
- Bluetooth MESH探究 --- (7) BLE core spec之为什么BLE能有更低功耗
- poj1637:Sightseeing tour(混合图欧拉回路,网络流)
- vue-cli脚手架的.babelrc文件 详解
- OSG 学习第四天:光照
- CSU-ACM2017暑假训练9-区间DP C
- 良好的编程习惯
- NFS的挂载
- 利用C语言编写一个通讯录,包括用户界面
- 2017 Multi-University Training Contest
- Android的日志工具Log
- KMP算法
- 三十天
- 有关散列表