Created
January 15, 2019 14:48
-
-
Save developer-sdk/8048e6698a475106e0f66db5821bbd08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package sdk.backjun.dp; | |
| import java.util.Scanner; | |
| /** | |
| * 백준, 5557 | |
| * 1학년 | |
| * | |
| * @author whitebeard-k | |
| * | |
| */ | |
| public class Problem5557 { | |
| static int N; | |
| static int[] nums; | |
| static long[][] memo; | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| N = sc.nextInt(); | |
| nums = new int[N+1]; | |
| memo = new long[21][N+1]; // 20 이하의 수만 처리 | |
| for(int i = 1; i <= N; i++) { | |
| nums[i] = sc.nextInt(); | |
| } | |
| sc.close(); | |
| memo[nums[1]][1] = 1; | |
| for(int y = 1; y < N-1; y++){ | |
| for(int num = 0; num <= 20; num++) { | |
| if(memo[num][y] != 0) { | |
| if(num + nums[y+1] <= 20) { | |
| memo[num + nums[y+1]][y+1] += memo[num][y]; | |
| } | |
| if(0 <= num - nums[y+1]) { | |
| memo[num - nums[y+1]][y+1] += memo[num][y]; | |
| } | |
| } | |
| } | |
| } | |
| System.out.println(memo[nums[N]][N-1]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment