fix: updated problem output since the numbers of combinations could be very high.
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
typedef long long ll;
|
||||
using namespace std;
|
||||
|
||||
int ways(string &s, int n, int idx = 0)
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
ll ways(string &s, int n, int idx = 0)
|
||||
{
|
||||
if (idx > n)
|
||||
return 1;
|
||||
@@ -14,11 +16,13 @@ int ways(string &s, int n, int idx = 0)
|
||||
if (idx + 1 < n)
|
||||
{
|
||||
int num = stoi(s.substr(idx, 2));
|
||||
if (num >= 10 && num <= 26)
|
||||
if (num >= 10 && num <= 26){
|
||||
count += ways(s, n, idx + 2);
|
||||
count %= MOD;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
return count % MOD;
|
||||
}
|
||||
|
||||
vector<bool> used;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
typedef long long ll;
|
||||
using namespace std;
|
||||
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
ll numDecodings(string s)
|
||||
{
|
||||
if (s[0] == '0')
|
||||
@@ -36,15 +38,17 @@ ll numDecodings(string s)
|
||||
if (current != '0')
|
||||
{
|
||||
dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
|
||||
dp[i][0] %= MOD;
|
||||
}
|
||||
|
||||
int code = stoi(aux);
|
||||
if (10 <= code && code <= 26)
|
||||
{
|
||||
dp[i][1] = dp[i - 2][0] + dp[i - 2][1];
|
||||
dp[i][1] %= MOD;
|
||||
}
|
||||
}
|
||||
return dp[N][0] + dp[N][1];
|
||||
return (dp[N][0] + dp[N][1]) % MOD;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
@@ -13,4 +13,4 @@ for i in range(1, n + 1):
|
||||
if 10 <= two_digit <= 26:
|
||||
dp[i] += dp[i - 2]
|
||||
|
||||
print(dp[n])
|
||||
print(dp[n] % 1000000007)
|
||||
@@ -3,6 +3,8 @@
|
||||
typedef long long ll;
|
||||
using namespace std;
|
||||
|
||||
const int MOD = 1e9 + 7;
|
||||
|
||||
ll numDecodings(string s)
|
||||
{
|
||||
if (s[0] == '0')
|
||||
@@ -20,12 +22,14 @@ ll numDecodings(string s)
|
||||
if (current != '0')
|
||||
{
|
||||
next = dp2;
|
||||
next %= MOD;
|
||||
}
|
||||
|
||||
int code = stoi(aux);
|
||||
if (10 <= code && code <= 26)
|
||||
{
|
||||
next += dp1;
|
||||
next %= MOD;
|
||||
}
|
||||
swap(dp1, dp2);
|
||||
swap(dp2, next);
|
||||
|
||||
Reference in New Issue
Block a user