SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iomanip>
  5. #include <random>
  6. #include <set>
  7.  
  8. using namespace std;
  9.  
  10. const int MAXN = 250;
  11.  
  12. int dp[MAXN][2];
  13.  
  14. int main() {
  15.     string s;
  16.     cin >> s;
  17.     dp[0][0] = 0;
  18.     dp[0][1] = 1;
  19.     for (int i = 1; i <= s.size(); ++i) {
  20.         dp[i][0] = min(dp[i - 1][0] + (s[i - 1] != 'R'),
  21.                 dp[i - 1][1] + (s[i - 1] != 'L') + 1);
  22.         dp[i][1] = min(dp[i - 1][1] + (s[i - 1] != 'L'),
  23.                 dp[i - 1][0] + (s[i - 1] != 'R') + 1);
  24.     }
  25.     cout << dp[s.size()][1];
  26.     return 0;
  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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top