还一道区间DP -- MZOJ 1346: 不老的传说
http://10.37.2.111/problem.php?id=1346
与上一道染色基本一样,就加了个限制条件(一次最多刷maxd)
#include <bits/stdc++.h>
#define read read()
#define up(i,l,r) for(int i = (l);i <=(r); i++)
using namespace std;
int read
{
int x = ; char ch = getchar();
while(ch < || ch > ) ch = getchar();
while(ch >= && ch <= ) {x = * x + ch - ; ch = getchar();}
return x;
}
const int N = ;
int n,c,maxn,f[N][N],a[N],ans = INT_MAX;
int main()
{
//freopen("spring.in","r",stdin);
memset(f,0x3f,sizeof(f));
n = read; c = read; maxn = read;
up(i,,n) a[i] = a[i + n] = read;
up(i,,((n<<) - )) f[i][i] = ;
up(L,,n)
up(i,,(n<<) - L)
{
int j = i + L - ;
if(a[i] == a[j])
{
if(j - i < maxn)//一定要加,最多能刷maxn; //-> 不加88(绵中数据太水了)
f[i][j] = min(f[i + ][j],f[i][j - ]);
}
else up(k,i,j - ) f[i][j] = min(f[i][j],f[i][k] + f[k + ][j]);
}
up(i,,n) ans = min(ans,f[i][i + n - ]);
printf("%d",ans);
return ;
}
还一道区间DP -- MZOJ 1346: 不老的传说的更多相关文章
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- 再一道区间DP -- P4170 [CQOI2007]涂色
https://www.luogu.org/problemnew/show/P4170 一道简单的区间DP,注意读入 #include <bits/stdc++.h> #define up ...
- [一道区间dp][String painter]
http://acm.hdu.edu.cn/showproblem.php?pid=2476 String painter Time Limit: 5000/2000 MS (Java/Others) ...
- 一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows
https://www.luogu.org/problemnew/show/P2858 方程很好想,关键我多枚举了一次(不过也没多大关系) #include <bits/stdc++.h> ...
- Blocks题解(区间dp)
Blocks题解 区间dp 阅读体验...https://zybuluo.com/Junlier/note/1289712 很好的一道区间dp的题目(别问我怎么想到的) dp状态 其实这个题最难的地方 ...
- 区间dp的典例
区间dp, 属于dp的一种,顾名思义,便是对区间处理的dp,其中石子归并,括号匹配,整数划分最为典型. (1)石子归并 dp三要素:阶段,状态,决策. 首先我们从第i堆石子到第j堆石子合并所花费的最小 ...
- HDU4632:Palindrome subsequence(区间DP)
Problem Description In mathematics, a subsequence is a sequence that can be derived from another seq ...
- 动态规划——区间dp
在利用动态规划解决的一些实际问题当中,一类是基于区间上进行的,总的来说,这种区间dp是属于线性dp的一种.但是我们为了更好的分类,这里仍将其单独拿出进行分析讨论. 让我们结合一个题目开始对区间dp的探 ...
- POJ2955:Brackets(区间DP)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
随机推荐
- Android 各个版本新特性
一.Android 4.x 新锁屏界面: Android4.0重新设计了锁屏幕UI,下方的解锁虚拟按键向周围发射出微光,轻轻拖动就可以解锁,比原来在UI上确实有很大的进步. 全新Widget排列: 主 ...
- Delphi: TMemo垂直滚动条自动显示
项目中碰到此问题,之前一直没留意,研究一番用上,以做备忘.参考其它解决方法,不尽完美,自试之,达到效果. 直上代码: type TMemo = class(StdCtrls.TMemo) protec ...
- 【Linux 线程】引出线程加锁问题
1.多线程的问题引入 多线程的最大的特点是资源的共享,但是,当多个线程同时去操作(同时去改变)一个临界资源时,会破坏临界资源.
- Hashed collections哈希集合
[定义] 有index的集合 [hash的原理] term for a situation when two different objects return the same hashcode: h ...
- ubuntu系统ssh遇到port 22:No route to host问题
ssh遇到这个port 22:No route to host这个问题 检查防火墙状态 (iptables -L) 检查ssh状态 (ps -elf |grep ssh) 检查网络状态(换根网线)
- javascript第一天知识点
JS的数据类型: 数字 number 字符串 string 布尔 boolean 空值 null 未定义的 undefined 数组 Array 对象 Object 通过typeof() 可以查看对 ...
- 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX(转)
原文地址:https://www.cnblogs.com/feng18/p/5646925.html 从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'g ...
- git查看历史操作
在提交了若干更新,又或者克隆了某个项目之后,偶尔想回顾下过往提交历史.可以使用git log命令来实现. 最简单的查看提交历史命令如下: $ git log $ git log --oneline $ ...
- ERROR: APK path is not specified for
1. 打开project structure 2.设置outpath路径 最好为绝对路径 点击确定 重新编译即可. Note: Android Studio版本使用
- go流程控制与函数
package main; import ( "fmt" ); func main() { isRun := true; //条件判断 if isRun { fmt.Printf( ...