1 test case is giving me TLE, but I am using bottom-up approach, my code:- https://ide.codingblocks.com/s/275851
Time Limit Exceeded
your approach is not correct
for(int row = n-1; row >= 0; --row) {
for(int col = 1; col <= target; ++col) {
bool include = false;
if(arr[row] <= col)
include = dp[row+1][col - arr[row]];
bool exclude = dp[row+1][col];
dp[row][col] = (exclude or include);
}
}
without calculate for dp[row][] how can you use value form dp[row+1][]
start row count form 1 instead of n