SHARE
TWEET

Gas Pipeline

a guest Aug 23rd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define MAX 200005
  3. using namespace std;
  4.  
  5. int t, n, a, b;
  6. char c;
  7. int thes[MAX];
  8.  
  9. int costfrom(int x, int layer) {
  10.     if (thes[x] == 0) {
  11.         int continuar = layer * b + a + costfrom(x+1, layer);
  12.         int descer = layer == 2 ? costfrom(x+1, layer-1) : -1;
  13.         int subir = layer == 1 ? cosfrom(x+1, layer+1) : -1;
  14.         return max(max(continuar, descer), subir);
  15.     }
  16. }
  17.  
  18. int main() {
  19.     cin >> t;
  20.     for (int i = 1; i <= t; i++) {
  21.         cin >> n >> a >> b;
  22.         for (int j = 1; j <= n; j++) {
  23.             cin >> c; thes[j] = c - '0';
  24.         }
  25.         cout << b + costfrom(0, 1) << "\n";
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top