2024/12/5 灵茶题单 dp

This commit is contained in:
Cool 2024-12-05 14:27:11 +08:00
parent 6a72586ba4
commit 24e1175d64
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package com.cool.ling_cha_mount.dp;
public class Num2466 {
public int countGoodStrings(int low, int high, int zero, int one) {
int[] dp = new int[high + 1];
dp[0] = 1;
int res = 0;
final int MOD = 1000000007;
for (int i = 1; i < dp.length; i++) {
if (i >= zero) {
dp[i] += dp[i - zero];
}
if (i >= one) {
dp[i] += dp[i - one];
}
dp[i] %= MOD;
if (i >= low) {
res += dp[i];
res %= MOD;
}
}
return res;
}
}