int find(vector<int> &A, int k, int n, vector<vector<int>> &t)
{
int p = 0;
//cout << "n: " << n << endl;
if(n <= 0 || k == 0)
{
return 0;
}
if(t[n][k] != -1)
{
return t[n][k];
}
for(int j = 0; j < n; j++)
{
p = A[n] - A[j] + find(A,k-1,j,t);
}
p = max(p,find(A,k,n-1,t));
t[n][k] = p;
cout << "n: " << A[n] << " p: " << p << endl;
return p;
}
int Solution::solve(vector<int> &A, int B)
{
int n = A.size();
vector<vector<int>> t(n+1);
for(int i = 0; i <= n; i++)
{
t[i] = vector<int>(B+1,-1);
}
cout << "calling..." << endl;
return find(A,B,n-1,t);
}