fix: updated problem output since the numbers of combinations could be very high.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -18,6 +18,8 @@ A segunda linha contém uma sequência de digitos de \( s \) de comprimento \( n
|
|||||||
|
|
||||||
A saída deve conter um único inteiro, representando o número total de maneiras possíveis de decodificar a sequência numérica \( s \) de acordo com o mapeamento \( 1 \rightarrow A, 2 \rightarrow B, \ldots, 26 \rightarrow Z \).
|
A saída deve conter um único inteiro, representando o número total de maneiras possíveis de decodificar a sequência numérica \( s \) de acordo com o mapeamento \( 1 \rightarrow A, 2 \rightarrow B, \ldots, 26 \rightarrow Z \).
|
||||||
|
|
||||||
|
Como este número pode ser extremamente grande, sua resposta deve ser calculada e impressa \textbf{módulo \(10^9 + 7\)}.
|
||||||
|
|
||||||
\ExemploEntrada
|
\ExemploEntrada
|
||||||
\begin{Exemplo}
|
\begin{Exemplo}
|
||||||
\texttt{2} & \texttt{2}\\
|
\texttt{2} & \texttt{2}\\
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1298777728820984005
|
782204094
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1836311903
|
836311896
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
typedef long long ll;
|
typedef long long ll;
|
||||||
using namespace std;
|
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)
|
if (idx > n)
|
||||||
return 1;
|
return 1;
|
||||||
@@ -14,11 +16,13 @@ int ways(string &s, int n, int idx = 0)
|
|||||||
if (idx + 1 < n)
|
if (idx + 1 < n)
|
||||||
{
|
{
|
||||||
int num = stoi(s.substr(idx, 2));
|
int num = stoi(s.substr(idx, 2));
|
||||||
if (num >= 10 && num <= 26)
|
if (num >= 10 && num <= 26){
|
||||||
count += ways(s, n, idx + 2);
|
count += ways(s, n, idx + 2);
|
||||||
|
count %= MOD;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count % MOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<bool> used;
|
vector<bool> used;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
typedef long long ll;
|
typedef long long ll;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
const int MOD = 1e9 + 7;
|
||||||
|
|
||||||
ll numDecodings(string s)
|
ll numDecodings(string s)
|
||||||
{
|
{
|
||||||
if (s[0] == '0')
|
if (s[0] == '0')
|
||||||
@@ -36,15 +38,17 @@ ll numDecodings(string s)
|
|||||||
if (current != '0')
|
if (current != '0')
|
||||||
{
|
{
|
||||||
dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
|
dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
|
||||||
|
dp[i][0] %= MOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = stoi(aux);
|
int code = stoi(aux);
|
||||||
if (10 <= code && code <= 26)
|
if (10 <= code && code <= 26)
|
||||||
{
|
{
|
||||||
dp[i][1] = dp[i - 2][0] + dp[i - 2][1];
|
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()
|
int main()
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ for i in range(1, n + 1):
|
|||||||
if 10 <= two_digit <= 26:
|
if 10 <= two_digit <= 26:
|
||||||
dp[i] += dp[i - 2]
|
dp[i] += dp[i - 2]
|
||||||
|
|
||||||
print(dp[n])
|
print(dp[n] % 1000000007)
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
typedef long long ll;
|
typedef long long ll;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
const int MOD = 1e9 + 7;
|
||||||
|
|
||||||
ll numDecodings(string s)
|
ll numDecodings(string s)
|
||||||
{
|
{
|
||||||
if (s[0] == '0')
|
if (s[0] == '0')
|
||||||
@@ -20,12 +22,14 @@ ll numDecodings(string s)
|
|||||||
if (current != '0')
|
if (current != '0')
|
||||||
{
|
{
|
||||||
next = dp2;
|
next = dp2;
|
||||||
|
next %= MOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = stoi(aux);
|
int code = stoi(aux);
|
||||||
if (10 <= code && code <= 26)
|
if (10 <= code && code <= 26)
|
||||||
{
|
{
|
||||||
next += dp1;
|
next += dp1;
|
||||||
|
next %= MOD;
|
||||||
}
|
}
|
||||||
swap(dp1, dp2);
|
swap(dp1, dp2);
|
||||||
swap(dp2, next);
|
swap(dp2, next);
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
A saída deve conter um único inteiro, representando o número total de maneiras possíveis de decodificar a sequência numérica \( s \) de acordo com o mapeamento \( 1 \rightarrow A, 2 \rightarrow B, \ldots, 26 \rightarrow Z \).
|
A saída deve conter um único inteiro, representando o número total de maneiras possíveis de decodificar a sequência numérica \( s \) de acordo com o mapeamento \( 1 \rightarrow A, 2 \rightarrow B, \ldots, 26 \rightarrow Z \).
|
||||||
|
|
||||||
|
Como este número pode ser extremamente grande, sua resposta deve ser calculada e impressa \textbf{módulo \(10^9 + 7\)}.
|
||||||
Reference in New Issue
Block a user