fork download
  1. // Author: __BruteForce__
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define MAX_C 30
  7. #define MOD (int)(1e9 + 7)
  8.  
  9. string str;
  10. int dp[MAX_C][2];
  11. int res = 0;
  12.  
  13. int main() {
  14. cin.tie(0)->sync_with_stdio(false);
  15.  
  16. cin >> str;
  17. for (int i = 0; i < (int)str.size(); i++) {
  18. int ch = str[i] - 'A';
  19. int temp = 0;
  20. for (int j = 0; j < ch; j++) {
  21. temp = (temp + dp[j][0]) % MOD;
  22. }
  23. res = (res + temp) % MOD;
  24. dp[ch][1] = (dp[ch][1] + temp) % MOD;
  25.  
  26. temp = 1;
  27. for (int j = ch + 1; j < 26; j++) {
  28. temp = (temp + dp[j][1]) % MOD;
  29. }
  30. res = (res + temp) % MOD;
  31. dp[ch][0] = (dp[ch][0] + temp) % MOD;
  32. }
  33.  
  34. cout << res << "\n";
  35. }
  36.  
Success #stdin #stdout 0.01s 5532KB
stdin
Standard input is empty
stdout
0