// NK
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef int ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define Bolivia_is_nice ios::sync_with_stdio(false), cin.tie(nullptr)
//typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ord_set;
int ma[100][100];
ll dp[100][100][10000];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int a,b,n,m;
ll f(int r, int c, int st){
if (st == -1){ // base case
if (r == a && c == b) return 0;
return -2;
}
//general case
ll &ans = dp[r][c][st];
if (ans != -1) return ans;
for (int i=0; i<4; i++){
int ro = r+dy[i];
int co = c+dx[i];
if (0<=ro && ro<n && 0<=co && co<m){
ll temp = f(ro, co, st-1) + ma[r][c];
ans = max(ans, temp);
}
}
return ans;
}
void solve(){
cin>>n>>m;
cin>>a>>b;
a--, b--;
int k; cin >> k;
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
cin >> ma[i][j];
}
}
memset(dp, -1, sizeof dp);
cout << f(a,b,k-1) << '\n';
}
int main(){
Bolivia_is_nice;
solve();
return 0;
}
/*
~/.emacs
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
45 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
41 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
42 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
49 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
46 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
51 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
48 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |