2 条题解

  • 2
    @ 2024-7-30 22:23:26
    #include<bits/stdc++.h>
    using namespace std;
    int dfs(const string &a, int pos, vector<int> &ovo, int mxcoin = 0,    int step1 = 0, int step2 = 0) {
        if (pos >= a.size())
            return 0;
        if (ovo[pos] != -1)
            return ovo[pos];
        if (a[pos] == '@')
            mxcoin = 1;
        if (pos + 1 < a.size() && a[pos + 1] != '*') 
            step1 = dfs(a, pos + 1, ovo);
        if (pos + 2 < a.size() && a[pos + 2] != '*') 
            step2 = dfs(a, pos + 2, ovo);
        ovo[pos] = mxcoin + max(step1, step2);
        return ovo[pos];
    }
    int main() {
        int t = 0;
        cin >> t;
        while (t--) {
            int n = 0;
            cin >> n;
            string a;
            cin >> a;
            vector<int> ovo(n, -1);
            cout << dfs(a, 0, ovo) << endl;
        }
        return 0;
    }
    

    非常好 dfs ,爱来自基沃托斯 感觉这样写比楼上优雅,故发题解 还有,熟悉的,不使用 vector 只能度过一个比较失败的人生(bushi

    信息

    ID
    715
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    (无)
    递交数
    63
    已通过
    19
    上传者