Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <string>
  5. #include <sstream>
  6. #include <algorithm>
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <map>
  10. #include <set>
  11. #include <list>
  12. #include <queue>
  13. #include <stack>
  14. #include <vector>
  15. #include <cassert>
  16.  
  17. using namespace std;
  18.  
  19. #define pb push_back
  20. #define mp make_pair
  21. #define REP(i, n) for (int i = 0; i < (int)(n); ++i)
  22. #define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); ++e)
  23. typedef long long LL;
  24. typedef pair<int, int> PII;
  25.  
  26. int tt, n, x, y, z, t;
  27. char a[2005], b[2005];
  28. vector<int> pos[2];
  29. int d[2001], dd[2001];
  30. const int INF = 2e9 + 1e7;
  31. int cost[2];
  32.  
  33. int main() {
  34.     scanf("%d", &tt);
  35.     REP(test, tt) {
  36.         scanf("%d%d%d%d%d", &n, &x, &y, &z, &t);
  37.         x *= 2, y *= 2, z *= 2;
  38.         scanf("%s%s", a, b);
  39.         REP(i, n) pos[b[i] - '0'].pb(i);
  40.         int mx = (int)pos[0].size();
  41.         REP(i, mx + 1) d[i] = INF;
  42.         d[0] = 0;
  43.         REP(i, n) {
  44.             REP(j, mx + 1) dd[j] = INF;
  45.             if (a[i] == '0') cost[0] = 0, cost[1] = x;
  46.             else if (a[i] == '1') cost[0] = y, cost[1] = 0;
  47.             else cost[0] = cost[1] = z;
  48.             REP(j, mx + 1) if (d[j] != INF) {
  49.                 if (j < mx) dd[j + 1] = min(dd[j + 1], d[j] + cost[0] + t * abs(pos[0][j] - i));
  50.                 if (i - j < n - mx) dd[j] = min(dd[j], d[j] + cost[1] + t * abs(pos[1][i - j] - i));
  51.             }
  52.             REP(j, mx + 1) d[j] = dd[j];
  53.         }
  54.         printf("%d\n", d[mx] / 2);
  55.         REP(i, 2) pos[i].clear();
  56.     }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement