还一道区间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 ...
随机推荐
- cetnos 7 增加新的硬盘
fdisk -l 查看新的硬盘是否挂载 如没有挂载 ls /sys/class/scsi_host/ 查看设备列表 echo "- - - " > /sys/class/sc ...
- AttributeError: 'dict' object has no attribute 'iteritems'
在python3.6中运行 sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse= ...
- CentOS 6 UNEXPECTED INCONSISTENCY RUN fsck MANUALLY
1:按Control-D,系统自动重启: 2:直接输入root的密码进入命令行 3:看网上的介绍需要输入mount |grep “on/” 找到root的分区,我试过后无效 4:直接输入fsck -y ...
- 贪吃蛇 Java实现(一)
贪吃蛇 Java实现 1.面向对象思想 1.创建antition包它是包含sanke Ground Food类 2.创建Controller包controller类 3.创建Game包有game类 ...
- unity的inputField文本框赋值问题
GameObject t = GameObject.Find("InputFieldT"); Text tt = t.transform.Find("Text" ...
- vue项目微信分享之后路由链接被破坏怎么办
异常现象: 多页面应用,路由采用hash模式,链接带有"#". 在微信中分享到朋友圈或好友时,分享出去的路由被破坏,打开分享的链接,路由中的“#”会被去掉并追加?fromTimel ...
- HDU 6315 Naive Operations(线段树区间整除区间)
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...
- Linux locales
一.简介 二.语法 三.实例 aptitude install locales dpkg-reconfigure locales ; vi /etc/default/locale more / ...
- 3A - Holding Bin-Laden Captive!
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But rec ...
- PDO 代码
<?php try{ $dsn = "mysql:dbname=mydb;host=localhost"; $pdo = new PDO($dsn,"root&qu ...