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都不能取了,问你最后取完最大的和是多少. ...
随机推荐
- H5实现的时钟
源码如下: <!doctype html> <html> <head></head> <body> <canvas id=" ...
- java static{}块
java中static{}块只有在类加载是才会被调用. 这说明:static只有可能被调用一次. 原因:首先理解什么是类加载,区分类加载和申明对象的区别. public class StaticTes ...
- DPM(Deformable Parts Model)
DPM(Deformable Parts Model) Reference: Object detection with discriminatively trained partbased mode ...
- windows和Ubantu双系统安装图解
Win7 U盘安装Ubuntu16.04 双系统详细教程 安装主要分为以下几步: 一. 下载Ubuntu 16.04镜像软件: 二. 制作U盘启动盘使用ultraISO: 三. 安装Ubuntu系统: ...
- 主动分布式WEB资产扫描
一. Redis的服务安装 系统环境:centos7x64 ip地址:192.168.1.11 1.设置静态IP地址 [root@localhost backlion]#vi /etc/sys ...
- JS的原生函数
常用的原生函数有: String() Number() Boolean() Array() Object() Function() RegExp() Date() Error() Symbol() 1 ...
- bzoj 1823: [JSOI2010]满汉全席 && bzoj 2199 : [Usaco2011 Jan]奶牛议会 2-sat
noip之前学的内容了,看到题竟然忘了怎么建图了,复习一下. 2-sat 大概是对于每个元素,它有0和1两种选择,必须选一个但不能同时选.这之间又有一些二元关系,比如x&y=1等等... 先把 ...
- 【数学】【CF1091D】 New Year and the Permutation Concatenation
Description 给定一个数 \(n\),将所有 \(1~\sim~n\) 的排列按照字典序放到一个序列中,求有多少长度为 \(n\) 的子序列 \(p_i~p_{i+1}~\dots~p_{i ...
- 2018java面试集合
作者:刘成链接:https://www.zhihu.com/question/266822548/answer/317700943来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- awk 脚本同时解析多个文件
ARGC The number of command line arguments (does not include options to gawk ...