I have asked this question on editorial of problem but no one replied so I have to raise this question as a new topic on the forum.
Here is link to problem SEEDLING and its EDITORIAL
This is my recursive backtracking code for 17 points. It is giving me 17 points.
I call solve(0, 0, 0) in my main function
long solve(int i, int space, int profit) {
if (space > s)
return 0;
if (i == n) {
if (space <= s && profit > 0)
return 1;
else
return 0;
}
return (solve(i, space + a[i], profit + c[i] - b[i]) + solve(i + 1, space, profit));
}
I want to pass the next subtask. I thought to do with recurssion with memoization. But its giving me TLE. Can anyone help me?
Now I am calling solve(0, 0, 3500) in my main function with dp size = new long[60][60][7000];
long solve(int i, int space, int profit) {
if (space > s)
return 0;
if (i == n) {
if (space <= s && profit > 3500)
return 1;
else
return 0;
}
if (dp[i][space][profit] != 0)
return dp[i][space][profit];
return dp[i][space][profit] = (solve(i, space + a[i], profit + p[i]) + solve(i + 1, space, profit));
}