Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <string>
- #include <sstream>
- #include <algorithm>
- #include <iostream>
- #include <iomanip>
- #include <map>
- #include <set>
- #include <list>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <cassert>
- using namespace std;
- #define pb push_back
- #define mp make_pair
- #define REP(i, n) for (int i = 0; i < (int)(n); ++i)
- #define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); ++e)
- typedef long long LL;
- typedef pair<int, int> PII;
- int tt, n, x, y, z, t;
- char a[2005], b[2005];
- vector<int> pos[2];
- int d[2001], dd[2001];
- const int INF = 2e9 + 1e7;
- int cost[2];
- int main() {
- scanf("%d", &tt);
- REP(test, tt) {
- scanf("%d%d%d%d%d", &n, &x, &y, &z, &t);
- x *= 2, y *= 2, z *= 2;
- scanf("%s%s", a, b);
- REP(i, n) pos[b[i] - '0'].pb(i);
- int mx = (int)pos[0].size();
- REP(i, mx + 1) d[i] = INF;
- d[0] = 0;
- REP(i, n) {
- REP(j, mx + 1) dd[j] = INF;
- if (a[i] == '0') cost[0] = 0, cost[1] = x;
- else if (a[i] == '1') cost[0] = y, cost[1] = 0;
- else cost[0] = cost[1] = z;
- REP(j, mx + 1) if (d[j] != INF) {
- if (j < mx) dd[j + 1] = min(dd[j + 1], d[j] + cost[0] + t * abs(pos[0][j] - i));
- if (i - j < n - mx) dd[j] = min(dd[j], d[j] + cost[1] + t * abs(pos[1][i - j] - i));
- }
- REP(j, mx + 1) d[j] = dd[j];
- }
- printf("%d\n", d[mx] / 2);
- REP(i, 2) pos[i].clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement