IT/알고리즘
[백준] 부분수열의 합
남갯
2024. 11. 6. 23:37
SMALL
https://www.acmicpc.net/problem/1182
fun main() = with(Scanner(System.`in`)) {
val n = nextInt()
val s = nextInt()
val arr = Array<Int>(n) { 0 }
for (i in 0 until n) {
arr[i] = nextInt()
}
var sCount = 0
fun total(cur : Int , sum : Int){
if(cur == n){
if(sum == s) sCount++
return
}
total(cur + 1, sum)
total(cur + 1, sum + arr[cur])
}
total(0,0)
if(s == 0) sCount--
println(sCount)
}
LIST