Advertisement
Guest User

Gas Pipeline

a guest
Aug 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement