Please read the new rule regarding the restriction on the use of AI tools. ×

How can I save state when learn dynamic programming with C++?

Revision en1, by tgbaodeeptry, 2021-05-21 10:17:53

Recently, I have been learning Dynamic Programming and I implemeted it:

int n, m, k;

bool can(int x, int y, int rem) {
    if (x > n || y > m || rem < 0)
        return false;

    if (x == n && y == m && rem == 0)
        return true;

    return can(x + 1, y, rem - y) || can(x, y + 1, rem - x); 
}

I want to save a 'state' contains: (x, y, rem) I tried to use map with tuple like: map<tuple<int, int, int>, bool> but syntax is not correct.

Thanks guy

Tags # dp, # 2d dp, #cpp

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English tgbaodeeptry 2021-05-21 10:17:53 551 Initial revision (published)