20250830 baekjoon
This commit is contained in:
parent
aa8cf25955
commit
1ef04d3377
20
code_study/Baekjoon/java/_1932.java
Normal file
20
code_study/Baekjoon/java/_1932.java
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
code_study/Baekjoon/swift/1932.swift
Normal file
20
code_study/Baekjoon/swift/1932.swift
Normal 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])
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user