티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | func solve(start: Int, end: Int, count: inout Int) -> Int{ if(start == 0){ return count + end } else{ for i in 1...end{ count = solve(start: start - 1, end: i, count: &count) } return count } } let input = Int(readLine()!)! var k = [Int]() var n = [Int]() for _ in 1...input{ k.append(Int(readLine()!)!) n.append(Int(readLine()!)!) } for i in 0..<k.count{ var count = 0 print(solve(start: k[i], end: n[i], count: &count)) } | cs |
재귀함수를 활용하여 푼다.
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
2908번 '상수' (0) | 2018.02.23 |
---|---|
2839번 '설탕 배달' (0) | 2018.02.23 |
2747번 '피보나치 수' (0) | 2018.02.23 |
2742번 '기찍 N' (0) | 2018.02.23 |
2741번 'N 찍기' (0) | 2018.02.23 |
댓글