题目链接: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)的更多相关文章

  1. CF1096D Easy Problem(DP)

    貌似最近刷了好多的CF题…… 题目链接:CF原网 洛谷 题目大意:有一个长度为 $n$ 的字符串 $s$,删除第 $i$ 个字符需要代价 $a_i$.问使得 $s$ 不含有子序列(不是子串)" ...

  2. (LightOJ 1004) Monkey Banana Problem 简单dp

    You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...

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

  4. Codeforces 1096D Easy Problem 【DP】

    <题目链接> 题目大意: 给你一个字符串,每个字符有权值,问现在删除字符串中的字符使其中没有"hard"的最小代价是多少. 解题分析: 用DP来求解:        转 ...

  5. 线段树:CDOJ1591-An easy problem A (RMQ算法和最简单的线段树模板)

    An easy problem A Time Limit: 1000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...

  6. CF1096:D. Easy Problem(DP)

    Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement ...

  7. D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) )

    D. Easy Problem dp(有衔接关系的dp(类似于分类讨论) ) 题意 给出一个串 给出删除每一个字符的代价问使得串里面没有hard的子序列需要付出的最小代价(子序列不连续也行) 思路 要 ...

  8. buaa 1033 Easy Problem(三分)(简单)

    Easy Problem 时间限制:1000 ms  |  内存限制:65536 KB 描写叙述 In this problem, you're to calculate the distance b ...

  9. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  10. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

随机推荐

  1. 实现Java中的ArrayList

    最近深受轮子哥影响,觉得造一些轮子应该会对自己的技术功底有一定的帮助,就决定先从简单的容器开始实现.废话不多说,就先实现一个Java中的ArrayList. ArrayList是我们在Java中使用非 ...

  2. ng-include 上ng-controller 无法获取控件

    A.Html内容如下 <div> <div kendo-grid="testGrid" k-options="testOptions"> ...

  3. P2461 [SDOI2008]递归数列

    题目描述 一个由自然数组成的数列按下式定义: 对于i <= k:ai = bi 对于i > k: ai = c1ai-1 + c2ai-2 + ... + ckai-k 其中bj 和 cj ...

  4. Powerful array CodeForces - 86D(莫队)

    给你n个数,m次询问,Ks为区间内s的数目,求区间[L,R]之间所有Ks*Ks*s的和.1<=n,m<=200000.1<=s<=10^6 #include <iostr ...

  5. 浅谈kmp

    简介: 一种由Knuth(D.E.Knuth).Morris(J.H.Morris)和Pratt(V.R.Pratt)三人设计的线性时间字符串匹配算法.这个算法不用计算变迁函数δ,匹配时间为Θ(n), ...

  6. SpringBoot之mongoTemplate的使用

    springboot的版本1.5.17.RELEASE. 1.mongo的IP和端口 在resources下的application.properties中加入如下内容 spring.data.mon ...

  7. 3Sum Closest - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 3Sum Closest - LeetCode 注意点 和3Sum那道题的target是0,这道题是题目给定的 要先计算误差再移动指针 解法 解法一:做法 ...

  8. JS的语法

    1.语句和表达式 var a = 3 * 6; var b = a; b; 这里,3 * 6是一个表达式(结果为18).第二行的a也是一个表达式,第三行的b也是.表达式a和b的结果值都是18. var ...

  9. Eureka的一些注意事项

    1.心跳设置:只能在application.yml中 2. 注册到Eureka上面的服务名称 与swagger2使用的时候,需要配置此项,否则显示服务名称为unknown 3.高可用的Eureka 4 ...

  10. Python【datetime】模块

    import datetimeprint("==============date类================")#创建一个date对象:datetime.date(year, ...