-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5557.cpp
More file actions
55 lines (48 loc) · 1.14 KB
/
5557.cpp
File metadata and controls
55 lines (48 loc) · 1.14 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @file 5557.cpp
* @brief 1학년
* @author Sam Kim (samkim2626@gmail.com)
*
* 못 풀어서 솔루션 참고. 문제 풀이, 접근 방법 다시 확인
*
* 2차원배열
* dp[i][j] : i번째 수까지 계산했을 때 j값을 만드는 올바른 등식의 수
* 1. j-num[i] >= 0 / 2. j+num[i] <= 20
*
* dp테이블 int -> long long (2^63-1)
*/
#include <iostream>
using namespace std;
int num[101];
long long dp[101][21];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> num[i];
}
dp[1][num[1]] = 1; // 첫 번째 수까지 경우의 수 초기화
for (int i = 2; i <= n; i++)
{
for (int j = 0; j <= 20; j++)
{
if (dp[i - 1][j] >= 0)
{
if (j - num[i] >= 0)
{
dp[i][j - num[i]] += dp[i - 1][j];
}
if (j + num[i] <= 20)
{
dp[i][j + num[i]] += dp[i - 1][j];
}
}
}
}
cout << dp[n - 1][num[n]] << '\n';
return 0;
}