-
Notifications
You must be signed in to change notification settings - Fork 1
12-dohyeondol1 #45
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
12-dohyeondol1 #45
Conversation
- μ λ΅ μ¬λΆμλ μν₯μ΄ μμ§λ§ μλͺ»λ μ΄κΈ°κ° μ€μ μμ
|
μ λ μ‘°ν©μΌλ‘ μ κ·Όν΄λ΄€μ΅λλ€. λ³κ³Ό λ§λλΌλ μ΄λ‘ μ μ¬μ©νμ΅λλ€. μμ:
|
|
@froglike6 |
hadongun
left a comment
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.
μκ°λ³΄λ€ κΈλ°© νΈμ μ μ¬μΈ μ€ μκ³ λ€λ³λ€κ° λκΉ λ§μλ€μ
μ νμμ ꡬνλ €κ³ kλ κ·Έλλ‘ λ μ±λ‘ n κ°μ΄ μ¦κ°ν λ λ§λ€ λ³νλ₯Ό κ΄μ°°νλλ°.. λ°κ²¬νμ§ λͺ»νμ΅λλ€.
μ κ° μκ°ν μ΄ μ νμμ ν΅μ¬μ nκ³Ό kμ λ³νλ₯Ό λμμ(?) 보λ κ²μ΄ ν΅μ¬μ΄ μλκΉ...νλ€μ
κ·Έλ κ² n,kλ₯Ό λμμ 보λ μ νμμ΄ λ³΄μ΄λκ΅°μ!
μ΄ν nμ΄ 0μΈκ²½μ°, kκ° 1μΈ κ²½μ° λͺ¨λ κ²½μ°μ μκ° 1μμ μ΄κΈ°ν νμ¬ λ¬Έμ λ₯Ό ν΄κ²°νμ΅λλ΅
νμ΄μ¬ coλ
n, k = map(int, input().split())
dp = [[0]*(k+1) for _ in range(n+1)]
for i in range(n+1):
dp[i][1] = 1
for i in range(k+1):
dp[0][i] = 1
for i in range(1, n+1):
for j in range(1, k+1):
dp[i][j] = dp[i-1][j] + dp[i][j-1]
print(dp[n][k]%1000000000)
caucsejunseo
left a comment
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.
νν΅ λ¬Έμ ν λ―μ΄ κ²½μ°μ μ λ°λΌ μκ°ν΄λ³΄λ©° μ΄ν΄νλ©΄μ νλ €κ³ νλλ° μλλ€μ...
λνλκ°μ μν κ³ μκ° μλλ©΄ κ·Έλ₯ μμ΄ λ¬Έμ ν λ―μ΄ κ·μΉλ§ μ°Ύλκ² λ ν¨μ¨μ μΈ κ² κ°μ΄λ€.
C
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define MOD 1000000000
int main() {
int n, k;
scanf("%d %d", &n, &k);
int dp[201][201] = { 0 };
for (int i = 0; i <= n; i++)
dp[1][i] = 1;
for (int i = 2; i <= k; i++)
{
for (int j = 0; j <= n; j++)
{
for (int l = 0; l <= j; l++)
{
dp[i][j] = (dp[i][j] + dp[i - 1][j - l]) % MOD;
}
}
}
printf("%d\n", dp[k][n]);
return 0;
}
π λ¬Έμ λ§ν¬
βοΈ μμλ μκ°
30λΆ! μ¬μ΄ DP λ¬Έμ λ μ‘°κΈμ© μκ°λ¨μΆμ΄ λμ΄κ°λ κ² κ°μ κΈ°μ©λλ€ γ γ
β¨ μλ μ½λ
0λΆν° NκΉμ§μ μ μ Kκ°λ₯Ό λν΄μ κ·Έ ν©μ΄ Nμ΄ λλ κ²½μ°μ μλ₯Ό ꡬνλ λ¬Έμ μ λλ€.
Warning
0λΆν° NκΉμ§μ μ μμ΄λ―λ‘, 0μ λν΄μ μ μμ κ°μλ₯Ό μ±μ°λ κ²½μ°λ ν¬ν¨ν΄μΌ ν©λλ€.
ex) 0λΆν° 1κΉμ§μ μ μ 2κ°λ₯Ό λν΄μ ν©μ΄ 1μ΄ λλ κ²½μ° : 1+0, 0+1 = 2κ°
μμ μ λ ₯μΈ
N = 20, K = 2μN = 6, K = 4λ₯Ό νμΈνκΈ° μν΄,0λΆν° iκΉμ§μ μ μ kκ°λ₯Ό λν΄μ ν©μ΄ iκ° λλ κ²½μ°μ μλ₯Ό i = 0 ~ 20, k = 0 ~ 6 μ ν μ΄λΈλ‘ μμ±νλ©΄ λ€μκ³Ό κ°μ΅λλ€.
μ κ° ν λ μ΄λ§νΌ λ§μ΄ μ°μ§ μμμ§λ§... μ΄λμ λ μ§μ κ²½μ°μμλ₯Ό ꡬν΄μ νλ₯Ό κ·Έλ €λ³΄λ©΄ κ·μΉμ μ°Ύμ μ μμ΅λλ€.
ν΄λΉ μ νμμ΄ μ μ©λμ§ μλ λ²μλ i = 0 μ΄κ±°λ, 0 β€ k β€ 1 μΌ κ²½μ°μ λλ€.
μ΄λ λ¨μν λ¬Έμ λλ‘ μ΄ν΄νλ©΄ μ¬μ΄λ°,
"0λΆν° 0κΉμ§μ μ μ kκ°λ₯Ό λν΄μ ν©μ΄ 0μ΄ λλ κ²½μ°μ μ"λ₯Ό ꡬνλ κ²μ΄λ―λ‘, μ¬μ©ν μ μλ μκ° 0νλλ°μ μμ΅λλ€.
λ€λ₯Έ μκ° μμΌλ―λ‘ κ°μλ§ μ±μμ§ λΏ ν©μ 0μΈ κ²½μ°μ μ νλλ§ μ‘΄μ¬νκ² λλ κ²μ΄μ£ .
λν kκ° 0μΌ κ²½μ° μ¬μ©ν μ μλ μ μκ° μμΌλ―λ‘ κ²½μ°μ μλ μ무κ²λ μ ννμ§ μλ κ²½μ° νλλ©°,
0λΆν° iκΉμ§μ μ μ λ²μμμ, κ°μ kκ° 1μΌ κ²½μ° ν©μ΄ iκ° λ μ μλ κ²½μ°λ μκΈ°μμ μ μ ννλ κ²½μ° νλμ λλ€.
λ°λΌμ μμ κ°μ λ²μμμμ μ΄κΈ°κ°μ μ€μ ν΄μ£Όκ³ ,
μμ ꡬν μ νμμ μ΄μ©ν΄ κ° κ²°κ³Όλ₯Ό 1,000,000,000μΌλ‘ λλ λλ¨Έμ§λ₯Ό ꡬνλ©΄ λ¬Έμ λ₯Ό ν΄κ²°ν μ μμ΅λλ€.
μλ μ½λ
2μ°¨μ DPλ μ²μ μ¬μ©ν΄λ³΄λλ° μ¬μ΄ λ¬Έμ λΌμ κΈλ°© νμμ΅λλ€.
DPλ νμ κ·μΉ μ°Ύλ μ¬λ―Έμ νλ κ² κ°μμ :D
PRμ μ°κ³ 보λ k = 0μΌ κ²½μ°λ κ΅³μ΄ λ°°μ΄μ ν¬ν¨νμ§ μμμ΄λ λ¬Έμ μμ΄ νμμ κ² κ°κΈ΄ νλ€μ
π μλ‘κ² μκ²λ λ΄μ©