-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrobot-reach.cpp
More file actions
32 lines (24 loc) · 778 Bytes
/
robot-reach.cpp
File metadata and controls
32 lines (24 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
template <typename T>
using V = std::vector<T>;
int sumDigits(int n) noexcept {
int res{ 0 };
while( n > 0 ) { res += n % 10; n /= 10; }
return res;
}
int main()
{
int r, c, t;
std::cin >> r >> c >> t; std::cin.ignore();
V< V<int> > mem{ static_cast<size_t>(r), V<int>(c, 0) };
for ( auto i{ 0 }; i < r; ++i )
for ( auto j{ 0 }; j < c; ++j )
mem[i][j] = sumDigits(i) + sumDigits(j);
std::function<int(int, int)> doTheJob{ [&](int row, int col){
if ( row >= r || col >= c || mem[row][col] > t )
return 0;
mem[row][col] = t + 1;
return doTheJob(row, col + 1) + doTheJob(row + 1, col) + 1;
} };
std::cout << doTheJob(0, 0) << '\n';
}