Friday, 14 December 2018

Solution to problem #1

#include<iostream>
using namespace std;

int count(int m, int n) {
if (m == 1 || n == 1) {
return 1;
}

else {
return count(m, n - 1) + count(m - 1, n);
}


}

int main() {
int m,n;
cin >>m>> n;
cout << count(m, n)<<endl;

}

I did this question using recursion we can also use DP(dynamic programming) in this. The time complexity of above solution is exponential.


Explanation of recursion is that we can come to (m,n-1) and take a step down or I can come to (m-1,n) and can take a right and come to (m,n). 

No comments:

Post a Comment

Dynamic programming problem

Given a binary matrix, find out the maximum size square sub-matrix with all 1s. For example, consider the below binary matrix. Please...