The code below works fine although a bit slow. In the function P I use a map m from int to long long to cache already calculated function values. However, I would prefer to map the arguments (n, k) directly to the function value without first transforming it to a single int (w = 1000 * n + k). I tried to do it with
map<vector<int, int>, longlong>
but it turned out to be painfully slow. How should this be done? I'm grateful for any helpful suggestions on this code.