Rod Cutting Problem Code I am learning dynamic programming. I read articles for the rod cutting problem and I applied it in cpp, and I got a doubt, does the below code solves the problem through memoization (say, previously rod(3) was solved, then if same function was called with same parameters) has the answer, or will it use tabulation (rodMax array), or uses both?

Since I read two different articles explaining different methods(memoization and tabulation, and read as two different methods to solve a dynamic problem), kind of confused on which method the below code runs. 

#include &lt;iostream&gt;

using namespace std;

int max(int a, int b){

    if(a &gt; b)
        return a;

    return b;
}

int arr[5] = {2, 4, 1, 2, 7};

int rodMax[5] = {-1, -1, -1, -1, -1};

int rod(int n){

    if(n &lt;=0)
        return 0;

    if(rodMax[n - 1] != -1){
        return rodMax[n];
    }

    int max_val = -1;
    for(int i = 0; i &lt; n; i++){

        max_val = max(max_val, arr[n-i-1]+rod(n-1));
    }
    //cout&lt;&lt;"\nmax "&lt;&lt;max_val&lt;&lt;endl;
    rodMax[n - 1] = max_val;

    return max_val;
}

int main() {

    cout&lt;&lt;"ans "&lt;&lt;rod(5)&lt;&lt;endl;
    //cout&lt;&lt;"ans "&lt;&lt;rod(3)&lt;&lt;endl;
    //for(int i = 0; i &lt;5; i++)
    //  cout&lt;&lt;rodMax[i]&lt;&lt;" ";
}
```
Don't using namespace std - especially if you're going to define a max() function in the global namespace (why not just use std::max() anyway?  That's what it's for!).

Where do the values in arr and rodMax come from?  Do their lengths have to agree?  If so, make that obvious in the code (e.g. use std::array, so that we can use arr.size() to count the members).