Algorithm to find max cost path of length N in matrix, from [0,0] to last row

后端 未结 4 940
走了就别回头了
走了就别回头了 2020-12-18 15:25

I have a n*n matrix, where each element represents an integer. Starting in [0,0] I have to find the path of exactly m elements down to

4条回答
  •  执念已碎
    2020-12-18 16:18

    This Question can be solved using recursion and backtracking. Keep the count of steps covered till now and the cost of path till now.

    Here is my implementation https://ideone.com/N6T55p

    void fun_me(int arr[4][4], int m, int n,int i,int j,int steps,int cost)
    {
    
    //cout<=n || j>=n)
        return;
    visited[i][j]=1;
    if(i==n-1 && steps==m-1)
    {
        if(maxer

提交回复
热议问题