Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя tgbaodeeptry

Автор tgbaodeeptry, история, 3 года назад, По-английски

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

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

Sure map<tuple<int, int, int>, bool> works

But it will be much faster to use just plain arrays. Map can be better if keys are too big and you know that there not that much states.