-
Notifications
You must be signed in to change notification settings - Fork 2
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
19-H0ngJu #202
Conversation
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.
Nκ°μ μ μ€ Kκ°λ₯Ό μ ννκΈ° -> μ‘°ν©? λ°±νΈλνΉ κ°μ¦μ~
νλλ° μ΅λ (200, 200)μ΄λ DPλ‘ κ²°κ³Ό μΊμ±ν΄μΌκ² λ€~ νκ³ DP ν
μ΄λΈ λλ± λ§λ€μλ€μ :)
#include <stdio.h>
#define MOD 1000000000
int N, K;
int dp[201][201];
int backtracking(int n, int k) {
if(n < 0) {
return 0;
} else if(k == 0) {
return n == 0;
} else if(dp[n][k] > 0) {
return dp[n][k];
} else {
for(int i = 0; i <= N; ++i) {
dp[n][k] += backtracking(n - i, k - 1);
dp[n][k] %= MOD;
}
return dp[n][k];
}
}
int main() {
scanf("%d%d", &N, &K);
printf("%d", backtracking(N, K));
return 0;
}
νμ€ν Top-down λ°©μμ΄ Bottom-upλ³΄λ€ λ리λ€μ :(
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.
μ DP μ€λλ§.....
import sys
def input(): return sys.stdin.readline().rstrip()
N, K = map(int, input().split())
DP = [[0 for _ in range(N+1)] for _ in range(K)]
for init in range(N+1):
DP[0][init] = 1
for step in range(1,K):
for plus_num in range(N+1):
for now_num in range(N-plus_num+1):
DP[step][now_num+plus_num] += DP[step-1][now_num]
print(DP[-1][-1]%1_000_000_000)
λλΆμ ν볡μ½λ©νμλλ€.................... λ°μ±ν©λλ€......
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~column κΉμ§ ν©μ κ³μ°νλλ° μ΄κ² (row, column-1) μ΄λ κ°λ€λκ±Έ κΉ¨λ«κ³ μμ νλλ μκ°μ΄ κ±°μ μ λ°μ»·..! μ¬λ°μμ΅λλΉ
μ½νλ¦°μ μ€λ²νλ‘ λλ¬Έμ Long νμ μ΄λΌλ λ§€λ² λλ¨Έμ§ κ³μ°μ ν΄μ€μΌνλ€μ©
import java.io.BufferedReader
import java.io.InputStreamReader
private lateinit var br: BufferedReader
fun main() {
br = BufferedReader(InputStreamReader(System.`in`))
val (N, K) = br.readLine().split(" ").map { it.toInt() }
val dp: Array<Array<Long>> = Array(K + 1) { row ->
Array(N + 1) { if (row == 1) 1 else 0 }
}
for (row in 2..K) {
dp[row][0] = dp[row - 1][0]
for (column in 1..N) {
dp[row][column] = (dp[row - 1][column] + dp[row][column - 1]) % 1_000_000_000L
}
}
println(dp[K][N] % 1_000_000_000L)
}
μ νμμ΄ μλ DP κΈ°λ³Έ λ¬Έμ μ λΉμ·ν΄μ λ°λ‘ λ μ€λ₯Έ λ¬Έμ κ°λ€μ!!! λ°λ‘ νμ£Όλ μ½λμ μμ λκ° γ·γ·γ·γ·γ· n, k = map(int,input().split())
dp = [[0] * (k+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(0, n+1):
for j in range(1, k+1):
dp[i][j] = dp[i-1][j] + dp[i][j-1]
print(dp[n][k] % 1_000_000_000) |
π λ¬Έμ λ§ν¬
ν©λΆν΄
βοΈ μμλ μκ°
20λΆ
β¨ μλ μ½λ
λ¬Έμ μμ½
0λΆν° NκΉμ§μ μ μ Kκ°λ₯Ό λν΄μ κ·Έ ν©μ΄ Nμ΄ λλ κ²½μ°μ μ λ°ννλΌ@! (λ¨, 1+2μ 2+1μ λ€λ₯Έ κ²½μ°λ‘ μκ°)
μ΄λ²μ ν볡 μ½λ©.. νμ΅λλ€
μλ μ νμλ μ¬μ΄ κ³λ¨ μμ μ μ¬ν΄μ!
κ·μΉλ§ μ°ΎμΌλ©΄ λλλ λ¬Έμ μ λλ€
κ·Έλ₯ K, N = 1λΆν° νλμ© νλ₯Ό 그리면
μ κ°μ΄λ©λλ€.
μ¦,
μ΄λ€ μ Nμ Kκ°μ μμ ν©μΌλ‘ λλλ κ²½μ°μ μλ
N-1μ Kκ°μ μμ ν©μΌλ‘ λνλ΄λ κ²½μ°μ μ
+Nμ K-1κ°μ μμ ν©μΌλ‘ λνλ΄λ κ²½μ°μ μ
μ λλ€.
λ°λΌμ κ³ λλ‘ μ½λ μμ±νλ©΄ λ!
π μλ‘κ² μκ²λ λ΄μ©