Codeforces 219C - Color Stripe - [DP]】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/219/C 题意: 给你 $n$ 个方块排成水平一排,每个方块都涂上 $k$ 种颜色中的一种.要求对尽量少的方块进行重新涂色,使得任意两个方块的颜色不同. 题解: $dp[i][x]$ 表示前 $i$ 个方块,第 $i$ 个方块颜色是 $x$,最少重新涂色多少个方块使得满足要求. AC代码: #include<bits/stdc++.h> using namespace std; const int I…
Color Stripe Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 219C Description A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors.…
题目链接:http://codeforces.com/problemset/problem/219/C 题目大意: 给出一个字符串,只包含k种字符,问最少修改多少个字符(不增长新的种类)能够得到一个新的字符串,这个字符串满足相邻的字符没有相同的.解题思路:k=2时:字符串只能是ABABAB.....或者BABABA.....两种都枚举一下即可.k>2时:若有奇数个相同,如AAAAA则可变为ABABA的形式即可.若有偶数个相同,如AAAAAA则变为ABABAC的形式即可,C保证与后一个不同. 代码…
ACM思维题训练集合 A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color…
1045 Favorite Color Stripe (30)(30 分) Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to…
题目链接 Favorite Color Stripe 题意:给定$A$序列和$B$序列,你需要在$B$序列中找出任意一个最长的子序列,使得这个子序列也是$A$的子序列 (这个子序列的相邻元素可以重复) 只要求出这个子序列长度的最大值即可 很基础的DP题,设$f[i]$为当前以$a[i]$结尾的子序列的长度的最大值,扫描$B$序列的每个元素时实时更新即可. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for…
题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN]; int main(void) { //…
1045 Favorite Color Stripe (30 分)   Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to f…
题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个正整数L(<=10000),代表条带的长度,接着输入L个正整数表示条带上的颜色的编号.输出以喜爱颜色顺序排列的最长子串长度(不必每种颜色都有,只保证相对位置相同,同种颜色可连续). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<b…
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form her favorite color stripe. It is…