Codeforces 1120C Compress String(DP)
题意:给你一个字符串,有2种消除方式:1:消除一个单独的字母,代价为a。2:s[j]到s[k]是s[1]到s[j - 1]的子串,那么s[j]到s[k]可以消除,代价为b,问最小的代价。
思路:官方题解说的很明白了。
代码:
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 5010;
int dp[maxn];
int v[maxn][maxn];
int Next[maxn];
char s[maxn];
int n, a, b;
int main() {
// freopen("inupt.txt", "r", stdin);
scanf("%d%d%d", &n, &a, &b);
scanf("%s",s + 1);
memset(dp, 0x3f, sizeof(dp));
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++) {
if(s[i] == s[j]) {
v[i][j] = v[i - 1][j - 1] + 1;
}
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
dp[i] = dp[i - 1] + a;
for (int j = 1; j < i; j++) {
int t = min(i - j, v[j][i]);
if(t) {
dp[i] = min(dp[i], dp[i - t] + b);
}
}
}
printf("%d\n", dp[n]);
}
Codeforces 1120C Compress String(DP)的更多相关文章
- codeforces#1120C. Compress String(dp+后缀自动机)
题目链接: https://codeforces.com/contest/1120/problem/C 题意: 从前往后压缩一段字符串 有两种操作: 1.对于单个字符,压缩它花费$a$ 2.对于末尾一 ...
- NYOJ 1067 Compress String(区间dp)
Compress String 时间限制:2000 ms | 内存限制:65535 KB 难度:3 描写叙述 One day,a beautiful girl ask LYH to help he ...
- [CareerCup] 1.5 Compress String 压缩字符串
1.5 Implement a method to perform basic string compression using the counts of repeated characters. ...
- [Codeforces 1201D]Treasure Hunting(DP)
[Codeforces 1201D]Treasure Hunting(DP) 题面 有一个n*m的方格,方格上有k个宝藏,一个人从(1,1)出发,可以向左或者向右走,但不能向下走.给出q个列,在这些列 ...
- [Algo] 611. Compress String II
Given a string, replace adjacent, repeated characters with the character followed by the number of r ...
- 【Codeforces 1120C】Compress String
Codeforces 1120 C 题意:给一个串\(S\),将这个串分成\(t_1..t_m\),如果\(t_i\)在\(t_1..t_{i-1}\)中作为子串出现过,那么这个的代价是\(b\),否 ...
- Educational Codeforces Round 16 E. Generate a String dp
题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...
- codeforces 825F F. String Compression dp+kmp找字符串的最小循环节
/** 题目:F. String Compression 链接:http://codeforces.com/problemset/problem/825/F 题意:压缩字符串后求最小长度. 思路: d ...
- codeforces 710E E. Generate a String(dp)
题目链接: E. Generate a String time limit per test 2 seconds memory limit per test 512 megabytes input s ...
随机推荐
- linux还原svn
仓库中版本的备份及还原形式主要有两种:方式一:直接备份仓库整个文件夹(全部版本),重装svn程序后直接还原过去.方式二:通过svn命令行备份和还原指定版本号的数据全备份:使用svnadmin hotc ...
- Net Core ElasticSearch入门
ElasticSearch入门 附.Net Core例子 https://www.cnblogs.com/CoderAyu/p/9564977.html 1.什么是ElasticSearch? Ela ...
- Python笔记-2
一.列表的定义及操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作. 1.列表的格式及赋值 列表,使用中括号括起来,元素之间用逗号隔开,列表中的元素具有明确的位 ...
- ERP与MES
EAS-ERP企业资源计划系统 能将企业的客户管理.商品管理.采购管理.仓储管理.销售管理.生产管理.应收应付.财务管理.工资管理.费用管理和业绩考核管理以及业务预警和全方位的分析汇总融为一体,为企业 ...
- c#同步調用異步(async)方法【記錄用】
使用RestSharp中的異步方法ExecuteTaskAsync<T>編寫寫了一個異步方法,功能很簡單:異步調用API,返回結果,假設為GetAccessToken,方法簽名假設如下: ...
- 从如何优化SQL入手,提高数据仓库的ETL效率
1 引言数据仓库建设中的ETL(Extract, Transform, Load)是数据抽取.转换和装载到模型的过程,整个过程基本是通过控制用SQL语句编写的存储过程和函数的方式来实现对 ...
- ubantu 虚拟机无法查看windows共享目录
初学linux,安装好虚拟机,安装好ubantu系统,启动系统后无法查看windows共享目录. 原因是没有安装 vmware tools 教程地址:http://www.linuxidc.com/L ...
- 【转】CentOs中Apache开启rewrite模块详解
rewrite是apache环境的一个伪静态功能了,如果我们没有没让Apache开启rewrite功能,网站上所有的rewrite规则都不可使用. centos的配置文件放在: /etc/httpd/ ...
- 数据的持久性存储(二)——CoreData(附Demo)
CoreData是一款稳定.功能全面的持久性工具.(本文参考iphone开发3所写,比较简要,需详细了解可以参考iphone开发3) 首先创建一个新的项目CoraData,记得勾选Use Core D ...
- jmeter 打不开 提示“Not able to find Java executable or version”的解决办法
Not able to find Java executable or version. Please check your Java installation . errorlevel=2Not a ...