본문 바로가기

IT

[백준] 카드구매하기 https://www.acmicpc.net/problem/11052 fun main() = with(Scanner(System.`in`)) { val count = nextInt() val array: Array = Array(count) { 0 } for (i in 0 until count) { array[i] = nextInt() } val dp = Array(array.size + 1) { 0 } for (i in array.indices) { dp[i + 1] = array[i] } for (i in 1 .. count) { for (j in 1 .. i) { dp[i] = max(dp[i], dp..
[백준] 1,2,3 더하기 https://www.acmicpc.net/problem/9095fun main() = with(Scanner(System.`in`)) { val number = nextInt() val array = Array(number) { 0 } for (i in array.indices) { array[i] = nextInt() } for (i in array) { var count = 0; fun dfs(total: Int) { if (total >= i) { if (total == i) { count++ } re..
[백준] 1로만들기 https://www.acmicpc.net/problem/1463 fun main() = with(Scanner(System.`in`)) { val size = nextInt() val count = Array(size + 1) { 0 } count[0] = 0 count[1] = 1 if (size == 1) { return println(0) } count[2] = 1 if (size == 2) { return println(count[size]) } count[3] = 1 if (size == 3) { return println(count[size]) } for (i in 4 until cou..
[백준] 2xn 타일링 https://www.acmicpc.net/problem/11726 fun main() = with(Scanner(System.`in`)) { val size = nextInt() val count = Array(size + 1) { 0 } count[0] = 0 count[1] = 1 if(size == 1){ return println(count[size]) } count[2] = 2 for (i in 3 until count.size) { count[i] = (count[i - 2] + count[i - 1]) % 10007 } println(count[size])}
[백준] 2xn 타일링2 https://www.acmicpc.net/problem/11727 fun main() = with(Scanner(System.`in`)) { val size = nextInt() val count = Array(size + 1) { 0 } count[0] = 0 count[1] = 1 if(size == 1){ println(count[1]) return } count[2] = 3 for (i in 3 until count.size) { count[i] = (count[i - 2] * 2 + count[i - 1]) % 10007 ..
[백준] 차이를 최대로 https://www.acmicpc.net/problem/10819 fun main() = with(Scanner(System.`in`)) { val count = nextInt() val visited = Array(count) { false } val array = Array(count) { 0 } for (i in array.indices) { array[i] = nextInt() } var result = 0 fun dfs(depth: Int, total: Int , current : Int) { if (depth == count - 1) { result = max(result, total) re..
[백준] 퇴사 https://www.acmicpc.net/problem/14501 fun main() = with(Scanner(System.`in`)) { val count = nextInt() val days: MutableList = mutableListOf() for (i in 0 until count) { val day = nextInt() val pay = nextInt() days.add(Days(day, pay)) } var result = 0 fun dfs(totalDays: Int, pay: Int) { if (totalDays count) continue dfs(i + days[i].day, pa..
[백준] 좋은수열 백트래킹을 통한 재귀구현이미 완성된 수열의 경우 좋은수열로 판단하여 추가로 들어오는 값에대한 앞과 뒤를 확인하면 된다. fun main() = with(Scanner(System.`in`)) { val count = nextInt() var result = "" fun backTracking(n: Int, str: String, index: Int) { if(!canMake(str)){ return } if (index == n) { if(result.isEmpty()){ result = str return } for(i..