2024/12/5 灵茶题单 dp
This commit is contained in:
parent
6a72586ba4
commit
24e1175d64
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue