From c7a060d7e9f61edb0c1f7d8bba368bf66d077d84 Mon Sep 17 00:00:00 2001 From: Dhruv Verma <75657801+Dhruvverma2020@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:13:16 +0530 Subject: [PATCH] Create Last Stone Weight II minimum subset problem --- ...ast Stone Weight II minimum subset problem | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Dynamic Programming/Last Stone Weight II minimum subset problem diff --git a/Dynamic Programming/Last Stone Weight II minimum subset problem b/Dynamic Programming/Last Stone Weight II minimum subset problem new file mode 100644 index 0000000..3c01211 --- /dev/null +++ b/Dynamic Programming/Last Stone Weight II minimum subset problem @@ -0,0 +1,45 @@ + int lastStoneWeightII(vector& stones) + { + int n=stones.size(); + int sum=0; + for(int i=0;ij) + { + dp[i][j]=dp[i-1][j]; + } + else if(stones[i-1]<=j) + { + dp[i][j]=dp[i-1][j-stones[i-1]]||dp[i-1][j]; + } + } + } + int maxi=0; + for(int j=0;j<=sum/2;j++) + { + if(dp[n][j]) + maxi=max(maxi,j); + } + return abs(2*maxi-sum); + }