https://practice.geeksforgeeks.org/problems/subset-sum-problem2014/1
Compilation error in my submission. Please explain the error and how to fix it
hello @
put loop (the one which u r using to initialise dp array ) inside the function.
equal parition function
The declaration of array dp[row][col] is being flagged as invalid too. why?
u r using row and col for dp size ,which is unknow before hand.
either give a fixed size . or declare dp array inside function after computng row and column ,
and then pass dp array to other function wheneve u need
I guess, the size isn’t unknown. See row and column being equal to N+1 and sum+1 respectively if the sum of elements is even. or 0 otherwise
I tried to give a fix size, but what would be a good size for the column part?
Given,
1<=N<=100
1 ≤ arr[i] ≤ 1000. So the sum can be 100000 at max, should i take dp[100][100000] ??
…
row and col is decided at the time of creating of object at the time of creating class u dont have it.
so if u want to delcare it as membe variable then u have to give fix size.
otherwise declare in functin.
ye this should work fine
Please see the updated code, it’s showing segmentation fault
pls share the updated code
becuase of too much memory allocation it is giving segfault.
use given row and colum to intialise dp array
or guess the sizw
Can you please share the code of your solution to the problem?
have already shared ur corrected code in my last response.
also u can check others solution from submissions section
Thanks
Btw, why did we do this? Can’t a class have any other statements except for functions and variables?
u can use dynamic array inside ur class if u want.
for statci array fixed size is necessary
i’m talking about putting the loop inside the function
…
you can…
for my convenience i replaced it , u can use loop
thank you
…
were u asking about loop inside class ? u can use loop only inside any function of class.
not anywhere else