EASY RECURSION->MEMOIZATION->TABULATION
Intuition\n Describe your first thoughts on how to solve this problem. \nCLASSIC WHICH PATH TO CHOSE\n# Approach\n Describe your approach to solving the problem
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCLASSIC WHICH PATH TO CHOSE\n# Approach\n<!-- Describe your approach to solving the problem. -->\nRECURSION->MEMOIZATION->TABULATION\nREAD COMMENTS\n\n# Complexity\n- Time complexity:O(F.N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N.F)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution \n{\n    int mod=1000000007;\n    public int countRoutes(int[] locations, int start, int finish, int fuel) \n    {\n        int n=locations.length;       \n        int dp[][] = new int[n][fuel+1];\n\n        //COMMENTED OUT FOR MEMOIZATION APPROACH\n        // for(int i=0;i<n;i++)\n        // {\n        //     for(int j=0;j<=fuel;j++)\n        //     {\n        //         dp[i][j]=-1;\n        //     }\n        // }\n        // return f(start,fuel,finish,locations,vis,dp);\n\n        //TABULATION APPROACH\n        for(int f=0;f<=fuel;f++)\n        {\n            dp[finish][f]=1;\n        }\n        \n        //SINCE FUEL FOLLOWS A STRICTLY DECREASING PATTERN,WE USE F AS THE FIRST LOOP AS I VARIES RANDOMLY\n        //THE FIRST LOOP IS ALWAYS OF A VARIABLE WHICH IS STRINCTLY INCREASING OR DECREASING RATHER THAN CHANGING BOTH WAYS\n        for(int f=0;f<=fuel;f++)\n        {\n            for(int i=0;i<n;i++)\n            {\n                for(int j=0;j<n;j++)\n                {\n                    if(j!=i && f>=Math.abs(locations[i]-locations[j]))\n                    {\n                        dp[i][f]=(dp[i][f] + dp[j][f-Math.abs(locations[i]-locations[j])])%mod;\n                    }\n                }\n                \n            }\n        }\n        return dp[start][fuel];\n\n    }\n\n    //RECURSION WITH MEMOIZATION APPROACH\n    public int f(int i,int fuel,int finish,int ar[],int vis[],int dp[][])\n    {\n        int ans=0;\n        if(i==finish)\n        {\n            ans=1;\n        }\n        if(dp[i][fuel]!=-1)\n        {\n            return dp[i][fuel];\n        }\n        for(int j=0;j<ar.length;j++)\n        {\n            if(j!=i && fuel>=Math.abs(ar[i]-ar[j]))\n            {\n                ans=(ans%mod+f(j,fuel-Math.abs(ar[i]-ar[j]),finish,ar,vis,dp)%mod)%mod;\n            }\n        }\n        dp[i][fuel]=ans;\n        return ans%mod;\n    }\n}\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Java']