SubsetSum { public static boolean existSubset(int sum, int[] array) { boolean[][] dp = new boolean[array.length][sum + 1]; for (int i = 0; i < array.length; i++) { dp[i][0] = true; } for (int i = 0; i < array.length; i++) { for (int j = 1; j <= sum; j++) { if (i == 0) { if (j == array[i]) { dp[i][j] = true; } } else { if (dp[i - 1][j] || j >= array[i] && dp[i - 1][j - array[i]]) { dp[i][j] = true; } } } } return dp[array.length - 1][sum]; }  static boolean existSubset(int sum, int[] array);  }
@Test(dataProvider = "testObjects") public void test(int sum, int[] array, boolean expected) { assertEquals(SubsetSum.existSubset(sum, array), expected); }