//https://www.acmicpc.net/problem/1495 #include <iostream> |
#include <queue> |
#include <math.h> |
using namespace std; |
bool dp[101][1001]; |
int V[101]; |
int main() |
{ |
int N, S, M; |
cin >> N >> S >> M; |
int x, y; |
for(int i=1; i<=N; i++) cin >> V[i]; |
dp[0][S]=1; |
for(int i=1; i<=N; i++) |
{ |
int x=pow(2,i); |
int a=0; |
for(int j=0; j<=M; j++) |
{ |
if(dp[i-1][j]) |
{ |
if(j-V[i] >=0 && j-V[i]<=M) dp[i][j-V[i]]=1; |
else a++; |
if(j+V[i] >=0 && j+V[i]<=M) dp[i][j+V[i]]=1; |
else a++; |
} |
if(a==x){ cout << "-1"; return 0;} |
} |
} |
int max=-1; |
for(int j=0; j<=M; j++) |
{ |
if(dp[N][j] && j>max) max=j; |
} |
cout << max; |
} |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
171130_2864_5와 6의 차이 (0) | 2017.11.30 |
---|---|
171129_1226_미로1 (0) | 2017.11.29 |
171128_1495_기타리스트 (큐 이용) (0) | 2017.11.28 |
171127_14891_톱니바퀴 (0) | 2017.11.27 |
171127_1476_날짜 계산 (0) | 2017.11.27 |