CF804B Minimum number of steps
Posted 王宜鸣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF804B Minimum number of steps相关的知识,希望对你有一定的参考价值。
思路:
找规律。参考了http://blog.csdn.net/harlow_cheng/article/details/71190999。
实现:
1 #include <iostream> 2 using namespace std; 3 const int mod = 1e9 + 7; 4 int main() 5 { 6 string s; 7 cin >> s; 8 int n = s.length(); 9 int cnt = 1; 10 int sum = 0; 11 for (int i = 0; i < n; i++) 12 { 13 if (s[i] == ‘a‘) cnt = cnt * 2 % mod; 14 else sum = (sum + cnt - 1) % mod; 15 } 16 cout << sum << endl; 17 return 0; 18 }
以上是关于CF804B Minimum number of steps的主要内容,如果未能解决你的问题,请参考以下文章
codeforce 804B Minimum number of steps
LeetCode 452. Minimum Number of Arrows to Burst Balloons
[LeetCode] 1419. Minimum Number of Frogs Croaking
LC 871. Minimum Number of Refueling Stops
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers