c_cpp https://arena.topcoder.com/#/u/practiceCode/1331/1747/1872/2/1331

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp https://arena.topcoder.com/#/u/practiceCode/1331/1747/1872/2/1331相关的知识,希望对你有一定的参考价值。

#include <bits/stdc++.h>

#define ll long long
#define sz(v) ((int) ((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep(i, v) for(int i = 0; i < sz(v); ++i)

using namespace std;

const int MAX = 5005;
const int OO = 1e9;


string bad1, bad2;
int n, l1, l2;
//ll cache[MAX];
map<string, ll> cache;

ll badStrings(string s) {
    int i = s.length();
    if(i == n) {
        //cout<< i << "   " << s << endl;
        return 1;
    }

    if(cache.find(s) != cache.end())
        return cache[s];

    ll &ret = cache[s];
    ret = 0;
    string tmps = s + 'A';
    if(i >= l1-1) {
        if(i >= l2-1) {
            if(tmps.substr(i-l1+1, l1) != bad1 && tmps.substr(i-l2+1, l2) != bad2)
                ret += badStrings(tmps);
        } else {
            if(tmps.substr(i-l1+1, l1) != bad1)
                ret += badStrings(tmps);
        }
    } else {
        if(i >= l2-1) {
            if(tmps.substr(i-l2+1, l2) != bad2)
                ret += badStrings(tmps);
        } else {
            ret += badStrings(tmps);
        }
    }

    tmps = s + 'B';
    if(i >= l1-1) {
        if(i >= l2-1) {
            if(tmps.substr(i-l1+1, l1) != bad1 && tmps.substr(i-l2+1, l2) != bad2)
                ret += badStrings(tmps);
        } else {
            if(tmps.substr(i-l1+1, l1) != bad1)
                ret += badStrings(tmps);
        }
    } else {
        if(i >= l2-1) {
            if(tmps.substr(i-l2+1, l2) != bad2)
                ret += badStrings(tmps);
        } else {
            ret += badStrings(tmps);
        }
    }
    tmps = s + 'C';
    if(i >= l1-1) {
        if(i >= l2-1) {
            if(tmps.substr(i-l1+1, l1) != bad1 && tmps.substr(i-l2+1, l2) != bad2)
                ret += badStrings(tmps);
        } else {
            if(tmps.substr(i-l1+1, l1) != bad1)
                ret += badStrings(tmps);
        }
    } else {
        if(i >= l2-1) {
            if(tmps.substr(i-l2+1, l2) != bad2)
                ret += badStrings(tmps);
        } else {
            ret += badStrings(tmps);
        }
    }
    return ret;
}
/*
int main() {
    cache.clear();
    cin>>n;
    cin>>bad1>>bad2;
    l1 = bad1.length();
    l2 = bad2.length();
    cout << badStrings("") << endl;
    return 0;
}*/

/*
NOTE: This is NOT Accepeted Solution.
*/

class BadSubstrings {
public:
    ll howMany(int n1, string b1, string b2) {
        cache.clear();
        n = n1;
        bad1 = b1;
        bad2 = b2;
        l1 = bad1.length();
        l2 = bad2.length();
        return badStrings("");
    }
};

以上是关于c_cpp https://arena.topcoder.com/#/u/practiceCode/1331/1747/1872/2/1331的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 127.单词阶梯

c_cpp MOFSET

c_cpp MOFSET

c_cpp 31.下一个排列

c_cpp string→char *

c_cpp 54.螺旋矩阵