Hello, I was wondering if there is a way of keeping last n rows of a matrix efficiently in C++, for example for DP?
Hello, I was wondering if there is a way of keeping last n rows of a matrix efficiently in C++, for example for DP?
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 4 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| Название |
|---|



In any language, the simplest approach is to just keep the array as
[n][width]instead of[height][width], and access elements as[row % n][col]instead of[row][col].What if i have something like this and i want to keep last t rows of dp but i am also updating the dp like so?
You have, for example (less lines to keep my comment short):
Transform it to:
Is it any different from what you initially asked?
Yeah that's what i was looking for, thanks a lot!