CF1096D Easy Problem

Posted wangyiming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF1096D Easy Problem相关的知识,希望对你有一定的参考价值。

思路:

dp[i][j]表示到第i个位置为止不能进入状态j所需要的最小代价。

实现:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 typedef long long ll;
 5 const ll INF = 0x3f3f3f3f3f3f3f3f;
 6 
 7 ll a[100005], dp[100005][5];
 8 
 9 int main()
10 {
11     int n; string s;
12     map<char, int> mp;
13     mp[h] = 1; mp[a] = 2; mp[r] = 3; mp[d] = 4;
14     while (cin >> n >> s)
15     {
16         for (int i = 0; i < n; i++) cin >> a[i];
17         dp[0][0] = INF;
18         for (int i = 1; i <= 4; i++) dp[0][i] = 0;
19         for (int i = 1; i <= n; i++)
20         {
21             for (int j = 0; j <= 4; j++) dp[i][j] = dp[i - 1][j];
22             if (mp.count(s[i - 1]))
23             {
24                 int tmp = mp[s[i - 1]];
25                 dp[i][tmp] = min(dp[i - 1][tmp - 1], dp[i - 1][tmp] + a[i - 1]);
26             }
27         }
28         ll ans = INF;
29         for (int i = 0; i <= 4; i++) ans = min(ans, dp[n][i]);
30         cout << ans << endl;
31     }
32     return 0;
33 }

 

以上是关于CF1096D Easy Problem的主要内容,如果未能解决你的问题,请参考以下文章

codeforces cf educatonal round 57(div2) D. Easy Problem

CF 1807

在核心数据中获取 Swift._SwiftDeferredNSArray' (0x1096d26b8) 到 'NSMutableArray

poj2826 An Easy Problem?!

CF802G Fake News (easy)

cf 模拟