C. Bouncing Ball:题目
很好的dp,1400分难见的题
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> a((int)6e5);
vector<int> b((int)6e5), c[(int)6e5];
const int mod = 1e9 + 7;
string s;
signed main()
{int t;cin >> t;while (t--){int n, p, k;cin >> n >> p >> k;cin >> s;int x, y;cin >> x >> y; // x是0变1,y是删除for (int i = 1; i <= n; i++){a[i] = s[i - 1] - '0';}int res = 0x3f3f3f3f;for (int i = p; i <= n; i++){b[i] = 0;if (a[i] == 0)b[i] = x;b[i] += (i - p) * y;}for (int i = p + k; i <= n; i++){if (a[i] == 0)b[i] = min(b[i], b[i - k] + x);elseb[i] = min(b[i], b[i - k]);}for (int i = n; i >= 0 && i >= n - k + 1&&i>=p; i--)res = min(res, b[i]);cout << res << endl;}
}