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