jain12

Count number of ways to cover a distance by dynamic prog.

May 27th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int PrintCountRec(int dist){
  5.   int arr[dist+1];
  6.   arr[dist]=1;
  7.   arr[dist-1]=1;
  8.   arr[dist-2]=2;
  9.   for(int i=dist-3;i>=0;i--)
  10.         arr[i]=arr[i+1]+arr[i+2]+arr[i+3];
  11.   return arr[0];
  12.   }
  13.  
  14.  int main(){
  15.    int dist =4;
  16.    cout<<PrintCountRec(dist);
  17.    return 0;
  18.    }
Add Comment
Please, Sign In to add comment