Similar Problems: leetcode.com/problems/partition-equal-subset-sum/ leetcode.com/problems/target-sum/ leetcode.com/problems/coin-change/
@JeevanKumar-code Жыл бұрын
Telegram Community Links: t.me/+FieKB7Ds6j02Y2Y1 t.me/+JU-ZF-oDjX4xYjBl
@tasneemayham974 Жыл бұрын
Sir, I thought about this problem like this: If I add up the totalTime and start with that: f(n,totalTime, T). If I went for not_take, totalTime will decrease by one and if I went for take, totalTime will increase by time[i]. If totalTime is greater than the start(T) then return 0 else return 1e9. Hence the dp will be [n+1][2*totalTime+1]. But it gives Memory Limit Exceeded. If I use your way which is [n][n+1], it will work. Mr. how should I know this is the correct way to solve starting from recursion? Thank you for your amazing videos bhaiya!!!
@dayashankarlakhotia4943 Жыл бұрын
public int paintWalls ( int []cost,int[]time){ int k=500000000; int n=cost.length; int []dp=new int [n+1]; Arrays.fill (dp,k); dp[0]=0; for(int i=0;i0;--walls) dp[walls]=Math.min (dp[walls],dp[Math.max (walls-time[i]-1,0)]+cost [i]; return dp[n]; }😢🎉😂❤