Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main( )
- {
- FILE *in = fopen("input.txt", "rt");
- FILE *out = fopen("output.txt", "wt");
- if (in && out)
- {
- int n, m;
- fscanf(in, "%d %d", &n, &m);
- int arr[n][m], mat[n][m];
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < m; ++j)
- {
- fscanf(in, "%d", &arr[i][j]);
- mat[i][j] = 0;
- }
- }
- mat[0][0] = 1;
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < m; ++j)
- {
- if (mat[i][j] && arr[i][j])
- {
- if (j + arr[i][j] < m)
- mat[i][j + arr[i][j]] += mat[i][j];
- if (i + arr[i][j] < n)
- mat[i + arr[i][j]][j] += mat[i][j];
- }
- }
- }
- fprintf(out, "%d", mat[n-1][m-1]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment