Codeforces Round #538 (Div. 2)D(区间DP,思维)
#include<bits/stdc++.h>
using namespace std;
int a[5007];
int dp[5007][5007];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
n=unique(a+1,a+1+n)-a-1;
for(int i=n;i>=1;i--){
for(int j=i+1;j<=n;j++){
dp[i][j]=min(dp[i+1][j]+1,dp[i][j-1]+1);//右面变为左面的颜色或者左面变为右面的颜色
if(a[i]==a[j])
dp[i][j]=min(dp[i][j],dp[i+1][j-1]+1);//里面变为外面的颜色
}
}
printf("%d",dp[1][n]);
return 0;
Codeforces Round #538 (Div. 2)D(区间DP,思维)的更多相关文章
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #538 (Div. 2) (CF1114)
Codeforces Round #538 (Div. 2) (CF1114) 今天昨天晚上的cf打的非常惨(仅代表淮中最低水平 先是一路缓慢地才A掉B,C,然后就开始杠D.于是写出了一个O( ...
- Codeforces Round #538 (Div. 2) D. Flood Fill 【区间dp || LPS (最长回文序列)】
任意门:http://codeforces.com/contest/1114/problem/D D. Flood Fill time limit per test 2 seconds memory ...
- Codeforces Round #538 (Div. 2)
目录 Codeforces 1114 A.Got Any Grapes? B.Yet Another Array Partitioning Task C.Trailing Loves (or L'oe ...
- Codeforces Round #369 (Div. 2) C 基本dp+暴力
C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树
https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...
- Codeforces Round #539 (Div. 2) 异或 + dp
https://codeforces.com/contest/1113/problem/C 题意 一个n个数字的数组a[],求有多少对l,r满足\(sum[l,mid]=sum[mid+1,r]\), ...
- Codeforces Round #131 (Div. 1) B. Numbers dp
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...
- Codeforces Round #131 (Div. 2) B. Hometask dp
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...
随机推荐
- 机器学习:SVM(非线性数据分类:SVM中使用多项式特征和核函数SVC)
一.基础理解 数据:线性数据.非线性数据: 线性数据:线性相关.非线性相关:(非线性相关的数据不一定是非线性数据) 1)SVM 解决非线性数据分类的方法 方法一: 多项式思维:扩充原本的数据,制造新的 ...
- Nor Flash的CFI与JEDEC接口
Flash 存储器接口还有两个标准:CFI和JEDEC.CFI为公共Flash接口[Common Flash Interface],用来帮助程序从Flash芯片中获取操作方式信息(发送命令,从nor ...
- 更加省心的服务,IntentService的使用
通过前两篇文章的学习,我们知道了服务的代码是默认运行在主线程里的,因此,如果要在服务里面执行耗时操作的代码,我们就需要开启一个子线程去处理这些代码.比如我们可以在 onStartCommand方法里面 ...
- python操作excel的读写
1.下载xlrd和xlwt pip install xlwd pip install xlrd pip install xlutils 2.读写操作(已存在的excel) #-*- coding:ut ...
- actionbar中添加searchview并监听期伸缩/打开的方法
首先在xml中设置actionviewclass <item android:id="@+id/m1" android:title="setting" a ...
- 在JAVA中,String,Stringbuffer,StringBuilder 的区别
首先是,String,StringBuffer的区别 两者的主要却别有两方面,第一是线程安全方面,第二是效率方面 线程安全方面: String 不是线程安全的,这意味着在不同线程共享一个String ...
- 算法Sedgewick第四版-第1章基础-1.4 Analysis of Algorithms-004计算内存
1. 2. 3.字符串
- java中下面这些引入都代表什么意思啊?
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; import java.uti ...
- python3-函数的参数的四种简单用法:
def print_two(*args): arg1, arg2 = args print "arg1: %r, arg2: %r" % (arg1,arg2) ...
- Java中常见设计模式面试
一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...