diff --git a/pu2rile/README.md b/pu2rile/README.md index fec575c..3ef787b 100644 --- a/pu2rile/README.md +++ b/pu2rile/README.md @@ -2,7 +2,7 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2024.03.24 | DP | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/3#issue-2205834078)| +| 1차시 | 2024.03.24 | 동적 프로그래밍 | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/3#issue-2205834078)| | 2차시 | 2024.03.29 | 구현 | [OX퀴즈](https://www.acmicpc.net/problem/8958) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/6#issue-2214931034)| | 3차시 | 2024.04.02 | 문자열 | [크로아티아 알파벳](https://www.acmicpc.net/problem/8958) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/10#issue-2220631332) | 4차시 | 2024.04.08 | 스택 | [제로](https://www.acmicpc.net/problem/10773) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/15#issue-2229909173) @@ -13,3 +13,4 @@ | 9차시 | 2024.05.27 | 구현 | [오늘도 졌다](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288) | 10차시 | 2024.07.11 | 스택 | [화학식량](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169) | 11차시 | 2024.07.13 | 우선순위 큐 | [강의실](https://www.acmicpc.net/problem/1374) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/37#issue-2406937336) +| 12차시 | 2024.07.23 | 동적 프로그래밍 | [1학년](https://www.acmicpc.net/problem/5557) | [#40](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/40) diff --git "a/pu2rile/\353\217\231\354\240\201 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/1\355\225\231\353\205\204.py" "b/pu2rile/\353\217\231\354\240\201 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/1\355\225\231\353\205\204.py" new file mode 100644 index 0000000..13cc18e --- /dev/null +++ "b/pu2rile/\353\217\231\354\240\201 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/1\355\225\231\353\205\204.py" @@ -0,0 +1,20 @@ +n = int(input()) +nums = list(map(int, input().split())) + +# dp 테이블 초기화 +dp = [[0] * 21 for _ in range(n)] # 0 이상 20 이하인 숫자이므로 크기가 21인 배열 + +# 첫 번째 숫자를 dp 테이블에 초기값으로 설정 +dp[0][nums[0]] = 1 + +# dp 테이블 채우기 +for i in range(1, n - 1): + for j in range(21): + if dp[i - 1][j]: + if j + nums[i] <= 20: # 더하기 + dp[i][j + nums[i]] += dp[i - 1][j] + if j - nums[i] >= 0: # 빼기 + dp[i][j - nums[i]] += dp[i - 1][j] + +# 마지막 숫자를 목표 값으로 만들 수 있는 경우의 수 출력 +print(dp[n-2][nums[-1]]) \ No newline at end of file