#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));
vector<vector<ll>> dp(n + 1,vector<ll>(n + 1, 0));
for (int i = 1;i <= n;i++) {
for (int j = 1; j <= n;j++) cin >> a[i][j];
}
dp[1][1] = 1;
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) dp[i + a[i][j]][j] += dp[i][j];
if (j + a[i][j] <= n) dp[i][j + a[i][j]] += dp[i][j];
}
}
cout << dp[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... |