题目:
代码(首刷看解析 2024年2月29日):
不晓得这种超过int和long的测试案例是用来恶心谁的,用DP都没机会取模
class Solution {
public:// 动态规划const int MOD = 1000000007;int numDistinct(string s, string t) {long n = s.size();long m = t.size();// dp + 初始化vector<vector<uint64_t>> dp(m + 1, vector<uint64_t>(n + 1, 0));for (int i = 0; i < n; ++i) dp[0][i] = 1;// 遍历 + 递推方程:先m(t)后n(s)for (int i = 1; i <= m; ++i) {for (int j = i; j <= n; ++j) {if (t[i - 1] == s[j - 1]) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];elsedp[i][j] = dp[i][j - 1]; }}//long res = dp[m][n];//res = (res % MOD + MOD) % MOD;return dp[m][n];}
};