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都不能取了,问你最后取完最大的和是多少. ...
随机推荐
- Linux进程调度策略的发展和演变(转)
转发:http://blog.csdn.net/gatieme/article/details/51701149 1 前言 1.1 进程调度 内存中保存了对每个进程的唯一描述, 并通过若干结构与其他 ...
- how to insert js to iframe page in order to disabled open new page/window
how to insert js to iframe page in order to disabled open new page/window js 禁用 iframe 中的页面打开新页面 htt ...
- .net MVC4 来一个简单的分页代码
action VodeEntities db = new NewVode.Models.VodeEntities(); ; ) { var sql = "select * ,row_numb ...
- PGM学习之一
一 课程基本信息 本课程是由Prof.Daphne Koller主讲,同时得到了Prof. Kevin Murphy的支持,在coursera上公开传播.在本课程中,你将学习到PGM(Probabil ...
- expect ssh 自动登录 example
#!/usr/bin/expect -f set ip [lindex $argv ] set port [lindex $argv ] set username [lindex $argv ] se ...
- STL stack 容器
STL stack 容器 Stack简介 stack是堆栈容器,是一种“先进后出”的容器. stack是简单地装饰deque容器而成为另外的一种容器. #include <s ...
- MT【137】多少个?
数列\(\{a_n\}\)共11项,\(a_1=0,a_{11}=4\),且\(|a_{k+1}-a_{k}|=2,k=1,2,\cdots,10\) 求满足条件的不同的数列的个数______ 解答: ...
- centos7下安装ossec
一.前言 OSSEC是一款开源的基于主机的入侵检测系统,可以简称为HIDS.它具备日志分析,文件完整性检查,策略监控,rootkit检测,实时报警以及联动响应等功能.它支持多种操作系统:Linux ...
- Codeforces 901C. Bipartite Segments(思维题)
擦..没看见简单环..已经想的七七八八了,就差一步 显然我们只要知道一个点最远可以向后扩展到第几个点是二分图,我们就可以很容易地回答每一个询问了,但是怎么求出这个呢. 没有偶数简单环,相当于只有奇数简 ...
- c++ 容器弊端
1.stack 不能直接清空,要 while (!s.empty()) s.pop(); 2.vector 增添.删除数据,也许vector首尾的地址会发生改变 如: ( watch f.begin( ...