baekjoon 20251210
This commit is contained in:
parent
9a663e093f
commit
289d125a19
39
code_study/Baekjoon/c/10844.c
Normal file
39
code_study/Baekjoon/c/10844.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define MOD 1000000000
|
||||||
|
long long dp[101][10];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
for (int i=1; i<10; i++) dp[1][i] = 1;
|
||||||
|
|
||||||
|
int N;
|
||||||
|
scanf("%d",&N);
|
||||||
|
|
||||||
|
for (int n=1; n<N; n++) {
|
||||||
|
for (int num=0; num<10; num++) {
|
||||||
|
|
||||||
|
if (dp[n][num] == 0) continue;
|
||||||
|
|
||||||
|
int next_num = num - 1;
|
||||||
|
if (0<=next_num && next_num <=9) {
|
||||||
|
dp[n+1][next_num] += dp[n][num];
|
||||||
|
dp[n+1][next_num] %= MOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
next_num = num + 1;
|
||||||
|
if (0<=next_num && next_num <=9) {
|
||||||
|
dp[n+1][next_num] += dp[n][num];
|
||||||
|
dp[n+1][next_num] %= MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long long result = 0;
|
||||||
|
for(int i=0; i<10; i++) {
|
||||||
|
result += dp[N][i];
|
||||||
|
result %= MOD;
|
||||||
|
}
|
||||||
|
printf("%lld\n",result);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
26
code_study/Baekjoon/python/15681.py
Normal file
26
code_study/Baekjoon/python/15681.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import sys
|
||||||
|
sys.setrecursionlimit(10**6)
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
N, R, Q = map(int, input().split())
|
||||||
|
|
||||||
|
edges = [[] for _ in range(N+1)]
|
||||||
|
|
||||||
|
for _ in range(N-1) :
|
||||||
|
u, v = map(int, input().split())
|
||||||
|
edges[u].append(v)
|
||||||
|
edges[v].append(u)
|
||||||
|
|
||||||
|
dp = [0]*(N+1)
|
||||||
|
|
||||||
|
def dfs(current, parent) :
|
||||||
|
dp[current] = 1
|
||||||
|
|
||||||
|
for next in edges[current] :
|
||||||
|
if next != parent :
|
||||||
|
dfs(next, current)
|
||||||
|
dp[current] += dp[next]
|
||||||
|
|
||||||
|
dfs(R, 0)
|
||||||
|
|
||||||
|
print("\n".join(map(str, [dp[int(input())] for _ in range(Q)])))
|
||||||
34
code_study/Baekjoon/swift/1806.swift
Normal file
34
code_study/Baekjoon/swift/1806.swift
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
func solve() {
|
||||||
|
guard let input1 = readLine(),
|
||||||
|
let NS = input1.split(separator: " ").compactMap({Int($0)}) as? [Int],
|
||||||
|
let N = NS.first, let S = NS.last
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
guard let input2 = readLine(),
|
||||||
|
let seq = input2.split(separator: " ").compactMap({Int($0)}) as? [Int]
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
var minLength = Int.max
|
||||||
|
var L = 0, R = 0
|
||||||
|
var acc = 0
|
||||||
|
|
||||||
|
while true {
|
||||||
|
if acc >= S {
|
||||||
|
minLength = min(minLength, R-L)
|
||||||
|
acc -= seq[L]
|
||||||
|
L += 1
|
||||||
|
}
|
||||||
|
else if R == N {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
acc += seq[R]
|
||||||
|
R += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = minLength == Int.max ? 0 : minLength
|
||||||
|
print(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
solve()
|
||||||
Loading…
x
Reference in New Issue
Block a user