Build a 2D DP Table
intro
Every DP problem starts the same way: declare the table. Do it from muscle memory.
Implement make_dp(n, m, fill) returning an n × m table (vector<vector<int>> in C++, list of lists in Python, array of arrays in JavaScript) with n rows and m columns, where every cell equals fill. Watch the row/column order: dp[i][j] must be valid for 0 <= i < n, 0 <= j < m.
Example: make_dp(2, 3, 0) returns {{0,0,0},{0,0,0}}: 2 rows, each holding 3 zeros.
Input format: each test in tests/*.in is laid out as:
- Line 1:
n m f, the three arguments tomake_dp(n, m, f): row count, column count, and fill value.
Test 03.in reads:
3 2 -1
This is a 3 x 2 table filled with -1.
Where you'll use it:
✦ Solution & editorial unlock with the pass.
Loading...