hdu6212[区间dp] 2017青岛ACM-ICPC网络赛
原题: BZOJ1032 (原题数据有问题)
/*hdu6212[区间dp] 2017青岛ACM-ICPC网络赛*/
#include <bits/stdc++.h>
using namespace std;
int T, n, tot = , kase = ;
char s[];
int dp[][], cnt[], col[];
void solve() {
memset(dp, 0x3f, sizeof(dp));
tot = ;
n = strlen(s);
cnt[tot] = , col[tot] = s[] - '';
for (int i = ; i < n; i++) {
if (s[i] == s[i - ]) cnt[tot]++;
else {
cnt[++tot] = ;
col[tot] = s[i] - '';
}
}
n = tot;
for (int i = ; i <= n; i++) dp[i][] = cnt[i] >= ? : ;
for (int j = ; j <= n; j++) {
for (int i = ; i + j - <= n; i++) {
if (col[i] == col[i + j - ]) {
if (cnt[i] + cnt[i + j - ] < ) {
dp[i][j] = dp[i + ][j - ] + (cnt[i] + cnt[i + j - ] == );
for (int k = ; k < j; k++) {
if (col[i + k - ] == col[i] && cnt[i + k - ] == ) {
dp[i][j] = min(dp[i][j], dp[i + ][k - ] + dp[i + k][j - k - ]);
}
}
}
else dp[i][j] = dp[i + ][j - ];
}
for (int k = ; k < j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[i + k][j - k]);
}
}
}
printf("Case #%d: %d\n", kase++, dp[][n]);
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%s", s);
solve();
}
return ;
}
// 011011100000001010101110011000 ans=4
// 10110011001101 ans=3
hdu6212[区间dp] 2017青岛ACM-ICPC网络赛的更多相关文章
- 2017 ICPC网络赛(西安)--- Xor
题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai≤1,000 ...
- Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
- 【2018ACM/ICPC网络赛】沈阳赛区
这次网络赛没有打.生病了去医院了..尴尬.晚上回来才看了题补简单题. K Supreme Number 题目链接:https://nanti.jisuanke.com/t/31452 题意:输入一个 ...
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1010
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1009
#include<cmath> #include<set> #include<list> #include<deque> #include<map ...
- Trace 2018徐州icpc网络赛 (二分)(树状数组)
Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...
- 2015年ACM长春网络赛(准备做掉7道:已经更新到6道)
总结汇总:模板 int getmax_min(char s[]) {//字符串的最大表示法:返回最小数组下标 , j = , k = ; while(i < len && j & ...
- 2013 acm 长沙网络赛 G题 素数+枚举 Goldbach
题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3856 先预处理求出两个素数的和与积,然后枚举n-prime和n/pr ...
- 近几年ACM/ICPC区域赛铜牌题
2013 changsha zoj 3726 3728 3736 3735 2013 chengdu hud 4786 4788 4790 2013 hangzhou hdu 4770 4771 47 ...
随机推荐
- Android(java)学习笔记100:使用Dexdump等工具进行反编译
使用Dex等工具进行反编译步骤: (1)首先找到Android软件安装包中的class.dex,把APK文件改名为".zip",然后解压缩其中的class.dex文件,这是Java ...
- 标准对象 -------JavaScript
本文摘要:http://www.liaoxuefeng.com/ 在JavaScript的世界里,一切都是对象. 但是某些对象还是和其他对象不太一样.为了区分对象的类型,我们用typeof操作符获取对 ...
- 后台调用前台js
WEB后台代码调用前台JS(两种方式). 1 这种方式只能调用简单的JS代码.不能调用自定义的函数. string jss = "<script language='javascr ...
- C的xml编程-libxml2
这里主要讲述libxml2在linux下的使用. (以下内容除了linux下的安装步骤是自己写的,其余均出自http://www.blogjava.net/wxb_nudt/archive/2007/ ...
- react的ant design的UI组件库
PC官网:https://ant.design/ 移动端网址:https://mobile.ant.design/docs/react/introduce-cn antd-mobile :是 Ant ...
- jquery简易的三级导航
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- 微信小程序text标签
最近在做小程序,使用<text>标签的时候发现里面的文本text-family不生效, 经过试验,发现直接在text标签的class设置不生效,可以在外层包一个父元素就可以设置了. < ...
- 转:maven国内镜像(maven下载慢的解决方法)
http://www.cnblogs.com/xiongxx/p/6057558.html https://jingyan.baidu.com/article/1876c8524ee0d0890a13 ...
- base64转图片上传
不成功,但是有一定的借鉴性 /** * @param base64Codes * 图片的base64编码 */ function sumitImageFile(base64Codes){ consol ...
- confirm() 方法用于显示一个带有指定消息和 OK 及取消按钮的对话框。系统自带提示
W3C地址::::::: http://www.w3school.com.cn/jsref/met_win_confirm.asp http://www.w3school.com.cn/tiy/t ...