首页 > 代码库 > CF804B Minimum number of steps

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