-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
17-Redish03 #73
17-Redish03 #73
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"files.associations": { | ||
"iostream": "cpp", | ||
"algorithm": "cpp" | ||
"algorithm": "cpp", | ||
"vector": "cpp" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <iostream> | ||
#define DVD 1000000000 | ||
|
||
using namespace std; | ||
|
||
int N; | ||
|
||
long long number_cnt = 0; | ||
long long dp[101][10] = { | ||
0, | ||
}; | ||
|
||
int main() | ||
{ | ||
cin >> N; | ||
for (int i = 1; i < 10; i++) | ||
{ | ||
dp[1][i] = 1; | ||
} | ||
for (int i = 2; i <= N; i++) | ||
{ | ||
for (int j = 0; j <= 9; j++) | ||
{ | ||
if (j == 0) | ||
{ | ||
dp[i][j] = dp[i - 1][1]; | ||
} | ||
else if (j == 9) | ||
{ | ||
dp[i][j] = dp[i - 1][8]; | ||
} | ||
else | ||
{ | ||
dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1]); | ||
} | ||
dp[i][j] %= DVD; | ||
} | ||
} | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
number_cnt += dp[N][i]; | ||
number_cnt %= DVD; | ||
} | ||
|
||
cout << number_cnt; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
long long dp[101] = { | ||
0, | ||
}; | ||
|
||
long long rec(int N) | ||
{ | ||
if (dp[N] != 0) | ||
{ | ||
return dp[N]; | ||
} | ||
if (N == 1 || N == 2 || N == 3) | ||
{ | ||
dp[N] = 1; | ||
return 1; | ||
} | ||
|
||
dp[N] = rec(N - 2) + rec(N - 3); | ||
return dp[N]; | ||
} | ||
Comment on lines
+9
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. νλ€μ΄ νμμ DPλ€μ! μ¬κ·λ₯Ό μ΄μ©νλ λ§νΌ κ°κ²°νκ³ μ§§μ μ½λμ μ₯μ , λλ¦° λ¨μ μ΄ μμ£ . λ§μ½ λͺ κ΅¬κ° κ±΄λλΈ μ μλ€λ©΄ λ κΈμ첨νκ² μ£ . (κ·Έλλ λ³΄ν΅ λ€ μ±μ°λ λ°ν μ μ΄ λ λΉ λ₯΄κΈ΄ ν©λλ€.) μ΄λ² μ νμμ, μ μκ°ν΄λ³΄λ©΄ κ²°κ΅ κ±°μ λͺ¨λ μΉΈμ΄ μ±μμ§λ€λ μ¬μ€μ μ μ μμ΅λλ€. μ μΌνκ² κ±΄λλ°λ μΉΈμ N-1μ΄μ£ . κ·Έλμ λ³ μν₯μ΄ μ... |
||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(0); | ||
cin.tie(0); | ||
cout.tie(0); | ||
|
||
int T, N; | ||
cin >> T; | ||
|
||
for (int i = 0; i < T; i++) | ||
{ | ||
cin >> N; | ||
cout << rec(N) << '\n'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ μ λ³μλ‘ λ°°μ΄μ μμ±νλ©΄, μλμ μΌλ‘ λ΄λΆ μμλ€μ΄ 0κ°μΌλ‘ μ΄κΈ°νλ©λλ€. λ°λ‘ 0μΌλ‘ μ΄κΈ°ν λͺ μλ₯Ό ν νμλ μλ΅λλΉ.