20250830 baekjoon

This commit is contained in:
songyc macbook 2025-08-30 21:20:47 +09:00
parent aa8cf25955
commit 1ef04d3377
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import java.util.*;
public class _1932 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
int[][] nums = new int[n][];
for(int i=0; i<n; i++) {
nums[i] = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer :: parseInt).toArray();
}
sc.close();
for(int i=n-2; i>=0; i--) {
for(int j=0; j<=i; j++) {
nums[i][j] += Math.max(nums[i+1][j],nums[i+1][j+1]);
}
}
System.out.println(nums[0][0]);
}
}

View File

@ -0,0 +1,20 @@
if let n = Int(readLine() ?? "0"){
var nums:[[Int]] = Array(repeating: Array(repeating: 0 , count: n), count: n)
for i in 0..<n {
if let input = readLine(), let numsLine = input.split(separator: " ").compactMap({Int($0)}) as? [Int], numsLine.count == i+1 {
for j in 0...i {
nums[i][j] = numsLine[j]
}
}
}
if n != 1 {
for i in (0...(n-2)).reversed() {
for j in 0...i {
nums[i][j] += max(nums[i+1][j],nums[i+1][j+1])
}
}
}
print(nums[0][0])
}