D. Easy Problem(简单DP)
题目链接:http://codeforces.com/contest/1096/problem/D
题目大意:给你一个字符串,然后再给你去掉每个字符串的每个字符的花费,然后问你使得字符中不再存在hard这个单词,可以是不连续的。
具体思路:我们从头开始,非hard的单词就不需要考虑了,然后考虑一下,当遇到a的时候,我们就考虑构成h的最小花费,当遇到har的时候,我们就考虑构成ha的最小花费,当遇到hard的时候,我们就考虑构成hard的最小花费就可以了。
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
# define inf 1ll<<
# define ll long long
ll dp[][maxn],cost[maxn];
char f[]= {"hard"};
string str;
ll n;
ll cal(int t1,int t2)
{
if(t1==)
return inf;
if(t2==n)
return ;
if(dp[t1][t2]!=-)
return dp[t1][t2];
if( str[t2] == f[t1])
{
dp[t1][t2] =min( cal(t1+,t2+), cal(t1,t2+)+cost[t2]);
}
else
{
dp[t1][t2] =cal(t1,t2+);
}
return dp[t1][t2];
}
int main()
{
cin>>n;
cin>>str;
for(int i=; i<n; i++)
{
cin>>cost[i];
}
// for(int i=0;i<4;i++){
// cout<<f[i]<<endl;
// }
memset(dp,-,sizeof(dp));
cout<<cal(,)<<endl;
return ;
}
D. Easy Problem(简单DP)的更多相关文章
- CF1096D Easy Problem(DP)
貌似最近刷了好多的CF题…… 题目链接:CF原网 洛谷 题目大意:有一个长度为 $n$ 的字符串 $s$,删除第 $i$ 个字符需要代价 $a_i$.问使得 $s$ 不含有子序列(不是子串)" ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
- HDOJ(HDU) 2123 An easy problem(简单题...)
Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...
- Codeforces 1096D Easy Problem 【DP】
<题目链接> 题目大意: 给你一个字符串,每个字符有权值,问现在删除字符串中的字符使其中没有"hard"的最小代价是多少. 解题分析: 用DP来求解: 转 ...
- 线段树:CDOJ1591-An easy problem A (RMQ算法和最简单的线段树模板)
An easy problem A Time Limit: 1000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...
- CF1096:D. Easy Problem(DP)
Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement ...
- D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )
D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...
- buaa 1033 Easy Problem(三分)(简单)
Easy Problem 时间限制:1000 ms | 内存限制:65536 KB 描写叙述 In this problem, you're to calculate the distance b ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
随机推荐
- js & Object reference bug
js & Object reference bug bug object ref bug onClickButton (type = ``) { let { publishDate: publ ...
- Augmenting DOM Storage with IE's userData behavior
http://www.javascriptkit.com/javatutors/domstorage2.shtml Augmenting DOM Storage with IE's userData ...
- 关于字符编码:ascii、unicode与utf-8
转自:https://foofish.net/unicode_utf-8.html 阮一峰老师对普及计算机基础技术功不可没,但毕竟老师不是神,因此也避免不了对某些概念有一些错误的理解,<字符编码 ...
- java的object类函数详解
1.clone方法(浅拷贝) 保护方法,实现对象的浅复制,只有实现了Cloneable接口才可以调用该方法,否则抛出CloneNotSupportedException异常. 主要是JAVA里除了8种 ...
- BZOJ 1180: [CROATIAN2009]OTOCI
1180: [CROATIAN2009]OTOCI Time Limit: 50 Sec Memory Limit: 162 MBSubmit: 989 Solved: 611[Submit][S ...
- linux系统之定制rpm包
FPM打包工具 FPM的作者是jordansissel FPM的github:https://github.com/jordansissel/fpm FPM功能简单说就是将一种类型的包转换成另一种类型 ...
- GreatSct -应用程序白名单bypass工具
0x00 GreatSCT简介 GreatSCT目前得到了@ConsciousHacker的支持,该项目名为Great SCT(Great Scott).Great SCT是一个用于生成应用程序白 ...
- JS的对象原型
1.对象 1.1 语法 对象可以通过两种形式定义:声明(文字)形式和构造形式. 对象的文字语法: var myObj = { key : value //... }; 对象的构造语法: var myO ...
- 【转】基于R语言构建的电影评分预测模型
一,前提准备 1.R语言包:ggplot2包(绘图),recommenderlab包,reshape包(数据处理) 2.获取数据:大家可以在明尼苏达州大学的社会化计算研 ...
- java程序文件读取与保存实例代码
class RadioHere extends JFrame implements ActionListener { private JTextArea ta=new JTextArea(10,20) ...