DP

很多小問題的最優解

字符計數

/*
 * zerojudge
 * c412. 四、多麼OwO(OwO)
 * NA 31%
*/
#include<bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;

int main() {
    int t;
    cin >> t;
    //---------------------------
    while(t--){
        int count = 0;
        int o_count = 0;
        int w_count = 0;
        char c=' ';
        while(cin >> c) {
            if(c=='O') {
                o_count+=1;
                //
                count+=w_count;
                count%=MOD;
            }else if (c=='w') {
                w_count+=o_count;
                w_count%=MOD;
            }else if(c=='\n'){
                break;
            }
        }
        //---------------------------
        cout << count << endl;
    }
    return 0;
}

//OwO 
// O++
// w+=O
// ans+=w

Last updated

Was this helpful?