Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ff first
- #define ss second
- #define pb push_back
- int main()
- {
- ll int x, y, z;
- cin>>x>>y>>z;
- string s;
- cin>>s;
- int n = s.size();
- ll int dp[n+1][2];
- dp[0][0] = 0;
- dp[0][1] = z;
- for(int i=0; i<n; i++)
- {
- if(s[i] == 'a')
- {
- dp[i+1][0] = min(dp[i][0]+x, z+x+dp[i][1]);
- dp[i+1][1] = min(dp[i][1]+min(x+2*z, y), z+x+dp[i][0]);
- }
- else
- {
- dp[i+1][1] = min(dp[i][1]+x, z+x+dp[i][0]);
- dp[i+1][0] = min(dp[i][0]+min(x+2*z, y), z+x+dp[i][1]);
- }
- dp[i+1][0] = min(dp[i+1][0], z+dp[i+1][1]);
- dp[i+1][1] = min(dp[i+1][1], z+dp[i+1][0]);
- }
- cout<<min(dp[n][1], dp[n][0])<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment