Created
December 9, 2019 17:52
-
-
Save resendes/593931d135f089173c0cd9d62b4f3037 to your computer and use it in GitHub Desktop.
This file contains 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
public int subsetSumDinamycProgramming() { | |
int[] x = {2,3,5,7,8,10,15}; | |
int t = 23; | |
int n = x.length; | |
int[][] s = new int[n+1][t+1]; | |
s[n][0] = 1; | |
for (int j = 1; j <= t; j++) { | |
s[n][j] = 0; | |
} | |
for (int i = n - 1; i >= 0; i--) { | |
s[i][0] = 1; | |
for (int j = 1; j <= x[i] - 1; j++) { | |
s[i][j] = s[i+1][j]; | |
} | |
for (int j = x[i]; j <= t; j++) { | |
int aux = s[i + 1][j]; | |
if (aux == 1) { | |
s[i][j] = aux; | |
} else { | |
s[i][j] = s[i + 1][j - x[i]]; | |
} | |
} | |
} | |
return s[0][t]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment