CF1096D Easy Problem [dp]

CF1096D Easy Problem

复习了几乎忘光了的dp

dp数组是这样子的:\(dp[i][0/1/2/3/4]\)表示前\(i\)个字符,"hard"遍历到了第几个字符的最小代价。

核心代码是这样的:

memset(dp, 0x3f, sizeof dp);
for(int i = 1; i <= 4; i++) dp[0][i] = 0;
for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= 4; j++) {
        if(ch[i] == str[j]) { // 从hard的上一个转移来不用删,否则要删
            dp[i][j] = std::min(dp[i - 1][j - 1], dp[i - 1][j] + a[i]);
        } else { // 从前面转移来,删了没意义
            dp[i][j] = dp[i - 1][j];
        }
    }
}

最后的答案是\(min(dp[n][1/2/3/4])\)。

原文地址:https://www.cnblogs.com/Garen-Wang/p/10349274.html

时间: 2024-10-04 02:37:15

CF1096D Easy Problem [dp]的相关文章

HDU 4359 Easy Tree DP?

Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1487    Accepted Submission(s): 567 Problem Description A Bear tree is a binary tree with such properties : each node has a value o

zoj 3791 An Easy Game dp

An Easy Game Time Limit: 2 Seconds      Memory Limit: 65536 KB One day, Edward and Flandre play a game. Flandre will show two 01-strings s1 and s2, the lengths of two strings are n. Then, Edward must move exact k steps. In each step, Edward should ch

HDU 4359——Easy Tree DP?——————【dp+组合计数】

Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1460    Accepted Submission(s): 557 Problem Description A Bear tree is a binary tree with such properties : each node has a value o

Easy Problem

D. Easy Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length nn

an easy problem(贪心)

An Easy Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8333   Accepted: 4986 Description As we known, data stored in the computers is in binary form. The problem we discuss now is about the positive integers and its binary form.

HDU2123 An easy problem【水题】

An easy problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5922    Accepted Submission(s): 4122 Problem Description In this problem you need to make a multiply table of N * N ,just like th

HDU2132 An easy problem【水题】

An easy problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10149    Accepted Submission(s): 2689 Problem Description We once did a lot of recursional problem . I think some of them is easy

poj2826An Easy Problem?!

链接 繁琐细节题. 1.线段无交点时,ans=0; 2.如图 假设过p3.y的水平线与p1p2相交 因为雨是垂直下落的,左图的情况是无法收集到雨水的 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath&g

Poj 2826 An Easy Problem?!

地址:http://poj.org/problem?id=2826 题目: An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13016   Accepted: 2003 Description It's raining outside. Farmer Johnson's bull Ben wants some rain to water his flowers. Ben nails tw