-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time: 17 ms (61.03%), Space: 20.3 MB (14.61%) - LeetHub
- Loading branch information
1 parent
c1adc83
commit cc378fb
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
2466-count-ways-to-build-good-strings/2466-count-ways-to-build-good-strings.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Solution { | ||
#define ll long long | ||
public: | ||
ll mod=1e9+7; | ||
ll c(ll len,ll low,ll high,vector<ll>&dp,int zero,int one){ | ||
if(len>high)return 0; | ||
if(dp[len]!=-1)return dp[len]; | ||
ll ans=0; | ||
if(len>=low && len<=high)ans=1; | ||
ans += c(len+zero,low,high,dp,zero,one)%mod; | ||
ans = (ans%mod + c(len+one,low,high,dp,zero,one)%mod)%mod; | ||
dp[len]=ans; | ||
return ans; | ||
} | ||
int countGoodStrings(int low, int high, int zero, int one) { | ||
vector<ll>dp(high+1,-1); | ||
return c(0,low,high,dp,zero,one); | ||
} | ||
}; |