#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
void solve() {
int n;
cin >> n;
vector<vector<int>> a(n + 1,vector<int>(n + 1));
auto dp = vector(n + 1,vector(n + 1,vector(105,0)));
for (int i = 1;i <= n;i++) {
for (int j = 1; j <= n;j++) cin >> a[i][j];
}
const int N = 104;
dp[1][1][N] = 1;
auto add = [&](int x,int y,int x1,int y1) {
auto d = dp[x1][y1];
auto d2 = dp[x][y];
int rem = 0;
for (int i = N; i > 1;i--) {
int cur = d[i] + d2[i] + rem;
rem /= 10;
cur %= 10;
d2[i] = cur;
}
dp[x][y] = d2;
};
for (int i = 1; i<= n;i++) {
for (int j = 1; j <= n;j++) {
if (a[i][j] == 0) continue;
if (i + a[i][j] <= n) add(i + a[i][j],j,i,j);
if (j + a[i][j] <= n) add(i,j + a[i][j],i,j);
}
}
bool ok = 0;
for (int i = 1; i < N;i++) {
if (dp[n][n][i] !=0 )ok = 1;
if (ok) cout << dp[n][n][i];
}
cout <<dp[n][n][N];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |