【动态规划】bzoj1939: [Croatian2010] Zuma
隐约记得类似的一道JSOI祖玛……然后好像这题不能够把珠子合并成一段?或许是因为这里珠子碰在一起之后可以不消除?
Description
Input
Output
Sample Input
3 3 3 3 2 3 1 1 1 3
Sample Output
题目分析
状态$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的更多相关文章
- Bzoj1939 [Croatian2010] Zuma
Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 43 Solved: 31 Description 有一行 N 个弹子,每一个都有一个颜色.每次可以让超过 ...
- 【BZOJ1939】[Croatian2010] Zuma(动态规划)
题目: BZOJ1939(权限题) 分析: 这题很容易看出是DP,但是状态和转移都不是很好想-- 用\(dp[l][r][c]\)表示在\(l\)前面已经新加了\(c\)个和\(l\)一样的弹子时,使 ...
- 「SPOJ6340」「BZOJ1939」ZUMA - ZUMA【记忆化搜索】
题目链接 [洛谷传送门] 题解 \(f[i][j][k]\)表示在消除了\((i,j)\),在后面加上了\(k\)个珠子的总的珠子数. 考虑三种决策:(题目给出的\(k\)在下文表示成\(K\)) 决 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 1032 JSOI2007 祖码Zuma 动态规划
题目大意:给定一个祖玛序列,任选颜色射♂出珠子,问最少射♂出多少珠子 输入法近期越来越奇怪了0.0 首先我们把连续同样的珠子都缩在一起 令f[i][j]表示从i開始的j个珠子的最小消除次数 初值 f[ ...
- Codeforces Round #336 Zuma
D. Zuma time limit per test: 2 seconds memory limit per test: 512 megabytes input: standard input ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
随机推荐
- React `controlled` 及 `uncontrolled` 组件
通过 props 来设置其 value 值的组件便是一种 controlled 组件.典型的 form 表单中,像 输入框 <input> 下拉框 <select> 多选框 & ...
- maven scope 以及依赖传递
https://www.cnblogs.com/mxm2005/p/4947905.html
- NSSM把.Net Core部署至 Windows 服务
NSSM把.Net Core部署至 Windows 服务 https://www.cnblogs.com/emrys5/p/nssm-netcore.html 为什么部署至Windows Servic ...
- Ubuntu上k8s集群里创建证书
证书: k8s里创建证书(使用证书文件命令创建): kubectl create secret tls scdsc-org-cn --cert=/etc/letsencrypt/live/scdsc. ...
- 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
- SqlDbx连接oracle
解压SqlDbx.zip,将SqlDbx放到C:盘根目录 1.Path里面增加:C:\SqlDbx Path是为了找tnsnames.ora 2.增加系统变量:ORACLE_HOME,路径:C:\S ...
- 牛客网Java刷题知识点之什么是匿名内部类、匿名内部类的使用原则、匿名内部类初始化、匿名内部类使用的形参为何要为final 和 案例
不多说,直接上干货! 什么是匿名内部类 匿名内部类就是没有名字的内部类. 不使用关键字class . extends .implements 没有构造函数 必须继承其他类或实现其他接口 正因为没有名字 ...
- hubbledotnet 使用笔记
Hubble vs 字符串 <connectionStrings> <add name="Search" connectionString="serve ...
- Spring MVC 示例
Srping MVC项目结构如下: 一.首先创建一个Dynamic Web Project 二.WebContent/WEB-INF/文件夹下新增 web.xml,配置servlet 容器对于web. ...
- 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. 人生最大的快乐是做到别人认为你做不到的事情.