c++ - How to handle very large matrices (e.g. 1000000 by 1000000) -


My question is very common..and its not a duplicate ..

When we like something Announce this as int mat [1000000] [1000000];

It is certain that this will give an error by saying the matrix size is too big.

I have seen many problems on many competitive programming websites where we need to declare a 2D matrix with 10 ^ 6 rows, columns, I know that to reduce the matrix size, always its There are some tricks attached to it.

That's why I just want to ask what can we do in the case of possible ways or tricks to reduce the size in such cases .. This means what type of algorithm is like a DP or someone else Need to solve ??

int mat [2] [1000000];

Code>. After calculating the existing row, you can immediately leave the previous row and switch the current and the previous.
  • Sometimes, it is possible to use the std :: map instead of the 2D array.
  • I have got many questions in programming competitions and the solution is substituted on a case-by-case basis, so if you mention a special case, then I can give you a better targeted solution.

  • Comments

    Popular posts from this blog

    Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

    multithreading - PhantomJS-Node in a for Loop -

    c++ - MATLAB .m file to .mex file using Matlab Compiler -