fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define mx 200005
  6.  
  7.  
  8.  
  9. ll c0, c1, h, dp[mx];
  10. int n;
  11. string s1;
  12.  
  13. ll func(int pos)
  14. {
  15. if(pos>=n)
  16. return 0;
  17. //ll &ret = dp[pos];
  18. ll a1=0, a2=0, a3=0;
  19. if(s1[0] == '0'){
  20. a1 = c0+func(pos+1);
  21. a2 = c1+h+func(pos+1);
  22. }
  23. else{
  24. a1 = c1+func(pos+1);
  25. a2 = c0+h+func(pos+1);
  26. }
  27. cout<< "check\n";
  28. return min(a1, a2);
  29. }
  30.  
  31. void solve()
  32. {
  33.  
  34. cin >> n >> c0 >> c1 >> h >> s1;
  35. cout << func(0) << "\n";
  36.  
  37. }
  38.  
  39. int main()
  40. {
  41. ios_base::sync_with_stdio(0);
  42. cin.tie(0);
  43.  
  44. int t=1;
  45. cin >> t;
  46.  
  47. while(t--)
  48. solve();
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0s 4492KB
stdin
1
5 1 1 1
11111
stdout
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
check
5