// dinamit.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <queue>
#define ll long long
using namespace std;
ll n, m, k;
ll dp[41][41][41];
ll x[41][41];
int main()
{
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)cin >> x[i][j];
for (int i = 1; i <= n; ++i)
{
ll mini = LLONG_MAX;
for (int l = 0; l <= k; ++l)
{
for (int o = 0; o <= l; ++o)
{
ll a = (pow(2, l - o));
mini = min(mini, dp[i - 1][1][o] + x[i][i] / a);
}
dp[i][1][l] = mini;
}
}
for (int j = 1; j <= n; ++j)
{
ll mini = LLONG_MAX;
for (int l = 0; l <= k; ++l)
{
for (int o = 0; o <= l; ++o)
{
ll a = (pow(2, l - o));
mini = min(mini, dp[1][j-1][o] + x[1][j] / a);
}
dp[1][j][l] = mini;
}
}
for (int i = 2; i <= n; ++i)
{
for (int j = 2; j <= m; ++j)
{
for (int l = 0; l <= k; ++l)
{
ll mini =LLONG_MAX;
for (int o = 0; o <= l; ++o)
{
ll a = (pow(2, l - o));
mini = min(mini,min(dp[i-1][j][o], dp[i][j-1][o]) + x[i][j] /a );
}
dp[i][j][l] = mini;
}
}
}
ll ans = LLONG_MAX;
for (int l = 0; l <= k; ++l)
ans = min(dp[n][n][l], ans);
cout << ans;
/*for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
for (int l = 0; l <= k; ++l)
{
cout << dp[i][j][l] << " ";
}
cout << " ";
}
cout << "\n";
}
*/
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
open /var/local/lib/isolate/405/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:18:19: error: 'LLONG_MAX' was not declared in this scope
18 | ll mini = LLONG_MAX;
| ^~~~~~~~~
main.cpp:6:1: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
5 | #include <queue>
+++ |+#include <climits>
6 | #define ll long long
main.cpp:23:25: error: 'pow' was not declared in this scope
23 | ll a = (pow(2, l - o));
| ^~~
main.cpp:31:19: error: 'LLONG_MAX' was not declared in this scope
31 | ll mini = LLONG_MAX;
| ^~~~~~~~~
main.cpp:31:19: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
main.cpp:36:25: error: 'pow' was not declared in this scope
36 | ll a = (pow(2, l - o));
| ^~~
main.cpp:48:26: error: 'LLONG_MAX' was not declared in this scope
48 | ll mini =LLONG_MAX;
| ^~~~~~~~~
main.cpp:48:26: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
main.cpp:51:29: error: 'pow' was not declared in this scope
51 | ll a = (pow(2, l - o));
| ^~~
main.cpp:58:14: error: 'LLONG_MAX' was not declared in this scope
58 | ll ans = LLONG_MAX;
| ^~~~~~~~~
main.cpp:58:14: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?