隐约记得类似的一道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. React `controlled` 及 `uncontrolled` 组件

    通过 props 来设置其 value 值的组件便是一种 controlled 组件.典型的 form 表单中,像 输入框 <input> 下拉框 <select> 多选框 & ...

  2. maven scope 以及依赖传递

    https://www.cnblogs.com/mxm2005/p/4947905.html

  3. NSSM把.Net Core部署至 Windows 服务

    NSSM把.Net Core部署至 Windows 服务 https://www.cnblogs.com/emrys5/p/nssm-netcore.html 为什么部署至Windows Servic ...

  4. Ubuntu上k8s集群里创建证书

    证书: k8s里创建证书(使用证书文件命令创建): kubectl create secret tls scdsc-org-cn --cert=/etc/letsencrypt/live/scdsc. ...

  5. Ubuntu 18.04 Python3.6.6导入wx模块报Gtk-Message : 17:06:05.797 :Failed to load module "canberra-gtk-module"

    解决办法: root@sishen:~# apt-get install libcanberra-gtk-module

  6. SqlDbx连接oracle

    解压SqlDbx.zip,将SqlDbx放到C:盘根目录 1.Path里面增加:C:\SqlDbx  Path是为了找tnsnames.ora 2.增加系统变量:ORACLE_HOME,路径:C:\S ...

  7. 牛客网Java刷题知识点之什么是匿名内部类、匿名内部类的使用原则、匿名内部类初始化、匿名内部类使用的形参为何要为final 和 案例

    不多说,直接上干货! 什么是匿名内部类 匿名内部类就是没有名字的内部类. 不使用关键字class . extends .implements 没有构造函数 必须继承其他类或实现其他接口 正因为没有名字 ...

  8. hubbledotnet 使用笔记

    Hubble vs 字符串 <connectionStrings> <add name="Search" connectionString="serve ...

  9. Spring MVC 示例

    Srping MVC项目结构如下: 一.首先创建一个Dynamic Web Project 二.WebContent/WEB-INF/文件夹下新增 web.xml,配置servlet 容器对于web. ...

  10. The great pleasure in life is doing what people say you cannot do.

    The great pleasure in life is doing what people say you cannot do.  人生最大的快乐是做到别人认为你做不到的事情.