隐约记得类似的一道JSOI祖玛……然后好像这题不能够把珠子合并成一段?或许是因为这里珠子碰在一起之后可以不消除?

Description

有一行 N 个弹子,每一个都有一个颜色。每次可以让超过 K 个的连续的同颜色的一段 弹子消失,剩下的会重新紧凑在一起。你有无限的所有颜色的弹子,要求在这行弹子中插入 最少的弹子,使得弹子全部消失。

Input

The first line of input contains two integers N (1 ≤ N ≤ 100) and K (2 ≤ K ≤ 5) - the number of marbles in the initial sequence and the minimal number of consecutive marbles of the same color he could wish to vanish. The next line contains exactly N integers between 1 and 100 (inclusive), separated by one space. Those numbers represent colors of marbles in the sequence Mirko found.

Output

The output should contain only one line with a single integer number - the minimal number of marbles Mirko has to insert to achive the desired effect.

Sample Input

10 4
3 3 3 3 2 3 1 1 1 3

Sample Output

4

题目分析

状态$f[i][j][k]$表示从第$i$个珠子到第$j$个珠子这一段,并在$j$后带有$k$个与$j$同色的珠子情况下的答案。

但实际上不甚明白这样表述状态的充要性。

 #include<bits/stdc++.h>
const int maxn = ; int n,m,K,tmp[maxn];
int a[maxn],c[maxn],f[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn]; int read()
{
char ch = getchar();
int num = ;
for (; !isdigit(ch); ch=getchar());
for (; isdigit(ch); ch=getchar())
num = (num<<)+(num<<)+ch-;
return num;
}
inline void Min(int &x, int y){x = x<y?x:y;}
int dp(int l, int r, int t)
{
if (l > r) return ;
if (vis[l][r][t]) return f[l][r][t];
vis[l][r][t] = ;
if (a[r]+t >= K) Min(f[l][r][t], dp(l, r-, ));
else Min(f[l][r][t], dp(l, r, t+1)+1); 
    //这里一开始想成dp(l, r, t-1)+1.实际上这里的状态表示的是逆推。也就是说f[]到完成消除的状态有多远。 
for (int k=l; k<r; k++)
if (c[k]==c[r])
Min(f[l][r][t], dp(l, k, t+)+dp(k+, r-, ));
return f[l][r][t];
}
int main()
{
memset(f, 0x3f3f3f, sizeof f);
n = read(), K = read();
for (int i=; i<=n; i++)
c[i] = read(), a[i] = ;
printf("%d\n",dp(, n, ));
return ;
}

END

【动态规划】bzoj1939: [Croatian2010] Zuma的更多相关文章

  1. Bzoj1939 [Croatian2010] Zuma

    Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 43  Solved: 31 Description 有一行 N 个弹子,每一个都有一个颜色.每次可以让超过 ...

  2. 【BZOJ1939】[Croatian2010] Zuma(动态规划)

    题目: BZOJ1939(权限题) 分析: 这题很容易看出是DP,但是状态和转移都不是很好想-- 用\(dp[l][r][c]\)表示在\(l\)前面已经新加了\(c\)个和\(l\)一样的弹子时,使 ...

  3. 「SPOJ6340」「BZOJ1939」ZUMA - ZUMA【记忆化搜索】

    题目链接 [洛谷传送门] 题解 \(f[i][j][k]\)表示在消除了\((i,j)\),在后面加上了\(k\)个珠子的总的珠子数. 考虑三种决策:(题目给出的\(k\)在下文表示成\(K\)) 决 ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. BZOJ 1032 JSOI2007 祖码Zuma 动态规划

    题目大意:给定一个祖玛序列,任选颜色射♂出珠子,问最少射♂出多少珠子 输入法近期越来越奇怪了0.0 首先我们把连续同样的珠子都缩在一起 令f[i][j]表示从i開始的j个珠子的最小消除次数 初值 f[ ...

  6. Codeforces Round #336 Zuma

    D. Zuma time limit per test:  2 seconds memory limit per test:  512 megabytes input:  standard input ...

  7. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  8. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  9. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

随机推荐

  1. 源码分析(一) 进程cleos的命令解析

    EOS版本:4.0   一.进程cleos的作用   cleos,即为client eos.从名字就可以猜出来,它是一个标准的客户端程序,而实际上,它也确实为一个标准的client^_^   准确地说 ...

  2. ldap 报错整理

    1.httpd 无法启动 先用systemctl status httpd 查看一下日志 1.提示端口号是否冲突,修改httpd.conf端口号 2.提示没有权限:检查selinux,防火墙是否关闭或 ...

  3. 黑马旅游网 ajax+html在前端实现页标签个数控制

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. PostgreSQL - invalid input syntax for type timestamp with time zone

    问题 在执行以下sql时报错: select COALESCE(null,null,now(),''); 报错如下: SQL Error [22007]: ERROR: invalid input s ...

  5. STP-10-RPVST+

    RPVST+(快速每VLAN生成树+)是一种以每个VLAN为基础,分别运行RSTP的形式,类似于PVST+.它拥有之前所描述的PVST+的优势,这为RSTP带来了亚秒级的收敛速度.因此,RPVST+和 ...

  6. python进阶12 Redis

    python进阶12 Redis 一.概念 #redis是一种nosql(not only sql)数据库,他的数据是保存在内存中,同时redis可以定时把内存数据同步到磁盘,即可以将数据持久化,还提 ...

  7. XML与JSON的区别

    JSON和XML的比较 ◆可读性 JSON和XML的可读性可谓不相上下,一边是简易的语法,一边是规范的标签形式,很难分出胜负. ◆可扩展性 XML天生有很好的扩展性,JSON当然也有,没有什么是XML ...

  8. Codeforces Round #562 (Div. 2) A.Circle Metro

    链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...

  9. python之is 和 == 的区别//编码和解码

    一.is  和  ==  的区别: 1  .id()   内存地址 2.  ==   比较    #比较两边的值 3.   is    比较   #比较的是内存地址 数字,字符串,有小数据池 #数字小 ...

  10. ORACLE索引的作用及用法

    https://blog.csdn.net/qq_34895697/article/details/52425289