Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- int **toxic = new int*[n];
- int **result = new int*[n];
- for (int i = 0; i < n; i++)
- {
- toxic[i] = new int[m];
- result[i] = new int[m];
- }
- for (int i = 0; i<n; i++)
- for ( int j = 0; j < m; j++)
- cin >> toxic[i][j];
- result[0][0] = toxic[0][0];
- for (int i = 1; i<n; i++)
- result[i][0] = result[i-1][0] + toxic[i][0];
- for (int j = 1; j<m; j++)
- result[0][j] = result[0][j-1] + toxic[0][j];
- for (int i = 1; i<n; i++)
- for ( int j = 1; j < m; j++)
- {
- result[i][j] = min(result[i-1][j], result[i][j-1]) + toxic[i][j];
- }
- cout << result[n-1][m-1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement