Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- vector<vector<int>>matrix(12,vector<int>(12,-1));
- int f(int i, int j){
- if (i == 1|| j == 1){
- return 1;
- }
- if(matrix[i][j] != -1){
- return matrix[i][j];
- }
- else{
- matrix[i][j]=f(i,j-1) + f(i-1,j);
- return matrix[i][j];
- }
- }
- int main() {
- int d,b,a,i,j,g,g1,m;
- cin>>a>>b;
- vector<vector<int>>A(a,vector<int>(b,-1));
- for (i=0; i < a; ++i){
- for (j = 0;j <b; ++j){
- cin>>A[i][j];
- }
- }
- g =1;
- g1 = 1;
- m = A[a-1][b-1];
- for (i=0; i > a+b-2; ++i){
- if(A[a-g-1][b-g1]<A[a-g][a-g1-1]){
- m = m + A[a-g-1][b-g1];
- g = g + 1;
- }
- else{
- m = m + A[a-g][a-g1-1];
- g1=g1+1;
- }
- }
- cout<<m;
- cout<<"\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment