I have recently started using vectors. In dynamic programming one generally needs large 2d array but there is a limit to size of 2d array which i can take(even “int a” produces error). So i am trying to do it with vectors but i am facing a problem.i am getting runtime error on execution of below statement in for loop
dp[i][j]=-1; (Code link)
whereas if i write something like “dp=-1” without loop, it works(Code link)
You cannot declare such a large array or vector! There is always limit to some space too. Try changing your logic of the DP so that you won’t need a double dimensional array.
here dp is an array of 100002 vector’s, which are initially empty .
case 1: you have inserted element without allocating memory to it.Thus for this case it would give segmentation fault.
case 2: Push_back adds an element to the end of vector, increasing its size by one