SHARE
TWEET

Letras

a guest Nov 12th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string.h>
  3. #include<map>
  4. using namespace std;
  5.  
  6. string s;
  7. map<char, map<int, bool>> viz;
  8. map<char, map<int, int>> dp;
  9.  
  10. int solve(char last, int i){
  11.     if(i >= s.size()) return 0;
  12.     if(viz[last][i]) return dp[last][i];
  13.     int L = 0;
  14.     if(last <= s[i]) L = 1 + solve(s[i], i+1);
  15.     int R = solve(last, i+1);
  16.     viz[last][i] = true;
  17.     return dp[last][i] = max(L, R);
  18. }
  19.  
  20.  
  21.  
  22. int main(){
  23.     cin >> s;
  24.     cout << solve('A',0) << endl;
  25. }
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