原题: 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网络赛的更多相关文章

  1. 2017 ICPC网络赛(西安)--- Xor

    题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai​≤1,000 ...

  2. 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 ...

  3. 【2018ACM/ICPC网络赛】沈阳赛区

    这次网络赛没有打.生病了去医院了..尴尬.晚上回来才看了题补简单题. K  Supreme Number 题目链接:https://nanti.jisuanke.com/t/31452 题意:输入一个 ...

  4. 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1010

    #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...

  5. 2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1009

    #include<cmath> #include<set> #include<list> #include<deque> #include<map ...

  6. Trace 2018徐州icpc网络赛 (二分)(树状数组)

    Trace There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx ...

  7. 2015年ACM长春网络赛(准备做掉7道:已经更新到6道)

    总结汇总:模板 int getmax_min(char s[]) {//字符串的最大表示法:返回最小数组下标 , j = , k = ; while(i < len && j & ...

  8. 2013 acm 长沙网络赛 G题 素数+枚举 Goldbach

    题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3856 先预处理求出两个素数的和与积,然后枚举n-prime和n/pr ...

  9. 近几年ACM/ICPC区域赛铜牌题

    2013 changsha zoj 3726 3728 3736 3735 2013 chengdu hud 4786 4788 4790 2013 hangzhou hdu 4770 4771 47 ...

随机推荐

  1. 【转】iOS开发之压缩与解压文件

    ziparchive是基于开源代码”MiniZip”的zip压缩与解压的Objective-C 的Class,使用起来非常的简单方法:从http://code.google.com/p/ziparch ...

  2. tk.mybatis Example 多个or条件拼接

    //需要的查询条件为 a and (b or c or d) 可以转换为 (a and b) or (a and c) or (a and d) private Example madeExample ...

  3. java调用摄像头

    http://blog.csdn.net/xing_sky/article/details/43482213 原文地址:http://blog.csdn.net/zajin/article/detai ...

  4. JS - 箭头函数与 () {} 的作用域

    foo () { // ... } 等价于 foo: function () { // ... } foo: () => { // ... } 范例: // 全局 name = 'zhangsa ...

  5. django+xadmin在线教育平台(二)

    老话总是没错的,工欲善其事,必先利其器 教你安装pycharm,mysql,navicat,python相关环境. windows下搭建开发环境 2-1 pycharm,mysql,Navicat安装 ...

  6. JS进阶篇--JS数组reduce()方法详解及高级技巧

    基本概念 reduce() 方法接收一个函数作为累加器(accumulator),数组中的每个值(从左到右)开始缩减,最终为一个值. reduce 为数组中的每一个元素依次执行回调函数,不包括数组中被 ...

  7. 27.28. VUE学习之--事件修饰符之stop&capture&self&once实例详解

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

  8. Hive 分析函数lead、lag实例应用

    Hive的分析函数又叫窗口函数,在oracle中就有这样的分析函数,主要用来做数据统计分析的. Lag和Lead分析函数可以在同一次查询中取出同一字段的前N行的数据(Lag)和后N行的数据(Lead) ...

  9. WPF异步回调时回调函数如何获取异步函数产生的变量

    有这么一个问题,WPF在使用异步回调的时候,回调函数需要用到异步函数里产生的一个变量,例如异步函数里查询数据库得到了一个DataTable,如何传递给回调函数呢? [方案一]使用全局变量 很容易想到的 ...

  10. RxJava Rxandroid retrofit

    其实Retrofit会了.集合RxJava,RxAndroid 就很简单了. 只需要改几个地方. 1.接口里面返回的对象不再是 call,而是Observable public interface A ...