DP Bash in CPP
Idk how people are getting all test cases to pass in this contest. I redid all of this with a dynamic programming bash. Lemme know if anyone had any similar app
Idk how people are getting all test cases to pass in this contest. I redid all of this with a dynamic programming bash. Lemme know if anyone had any similar approach...\n```\nclass Solution {\nprivate:\n    const int mod = 1000000007;\n\npublic:\n    int stringCount(int n) {\n        if (n < 4) return 0;\n        std::vector<std::vector<std::vector<std::vector<long>>>> dp(\n            n + 1, std::vector<std::vector<std::vector<long>>>(\n                2, std::vector<std::vector<long>>(\n                    3, std::vector<long>(2, -1)\n                )\n            )\n        );\n        return static_cast<int>(f(n, 0, 0, 0, 0, dp) % mod);\n    }\n\nprivate:\n    long f(int n, int l, int e, int t, int i, std::vector<std::vector<std::vector<std::vector<long>>>>& dp) {\n        if (i == n) {\n            if (l >= 1 && e >= 2 && t >= 1) return 1;\n            return 0;\n        }\n\n        if (l > 1) l = 1;\n        if (e > 2) e = 2;\n        if (t > 1) t = 1;\n\n        if (dp[i][l][e][t] != -1) return dp[i][l][e][t];\n\n        long ans = 0;\n\n        for (char j = \'a\'; j <= \'z\'; ++j) {\n            if (j == \'l\') {\n                ans += f(n, l + 1, e, t, i + 1, dp);\n            } else if (j == \'e\') {\n                ans += f(n, l, e + 1, t, i + 1, dp);\n            } else if (j == \'t\') {\n                ans += f(n, l, e, t + 1, i + 1, dp);\n            } else {\n                ans += f(n, l, e, t, i + 1, dp);\n            }\n        }\n\n        return dp[i][l][e][t] = (ans % mod);\n    }\n};\n```
[]