自学内容网 自学内容网

牛客习题—线性DP 【mari和shiny】C++

你好,欢迎阅读我的文章~

个人主页:@Mike

所属专栏:动态规划



mari和shiny

mari和shiny

分析:

使用动态规划的思路来解决。

思路:

        分别统计s,sh,shy的数量即可。使用ss来统计字符s的数量,使用sh来统计字符sh的数量,使用shy来统计字符shy的数量。

代码实现:

十年OI一场空,不开longlong见祖宗。

#include<stdlib.h>
#include<iostream>
using namespace std;
#define int long long


signed main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ss=0;
    int sh=0;
    int shy=0;
    
    for(int i=0;i<n;i++)
    {
        if(s[i]=='s')
        {
            ss++;
        }
        else if(s[i]=='h')
        {
            sh=sh+ss;
        }
        else if(s[i]=='y')
        {
            shy=shy+sh;
        }
    }
    
    cout<<shy<<endl;
    
}



原文地址:https://blog.csdn.net/2301_80122797/article/details/143062499

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!