백준 1182 nodejs

윤익·2022년 10월 28일
0

https://www.acmicpc.net/problem/1182

const fs = require('fs')
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n')

const [N, S] = input[0].split(' ').map(Number)
const A = input[1].split(' ').map(Number)

function dp(i, S) {
  if (i == 0) return S == A[0] ? 1 : 0
  const n = A[i] == S ? 1 : 0 
  return dp(i - 1, S) + dp(i - 1, S - A[i]) + n
  // A[i] 포함 여부에 따라 분할 [...] + [..., A[i]] + [A[i]]
}

console.log(dp(N - 1, S))
profile
https://nickyoon.tistory.com/ 기술 블로그 이전

0개의 댓글