brute force with memoization
\nclass Solution {\npublic:\n    \n    int mod = 1e9+7;\n    int solve(vector<int> &a,int s, int e, int f,vector<vector<int>> &c)\n    {\n        if(f==0 && s==
```\nclass Solution {\npublic:\n    \n    int mod = 1e9+7;\n    int solve(vector<int> &a,int s, int e, int f,vector<vector<int>> &c)\n    {\n        if(f==0 && s==e)\n            return 1;\n        else if(f==0)\n            return 0;\n        \n        \n        if(c[s][f]!=-1)\n            return c[s][f];\n            \n        int ans = 0;\n        if(s==e)\n            ans=1;\n        \n        for(int i=0;i<a.size();i++)\n        {\n            if(i==s)\n                continue;\n            \n            if(abs(a[s]-a[i])<=f)\n            {\n                ans = (ans%mod + solve(a,i,e,(f-(abs(a[s]-a[i]))),c)%mod)%mod;\n            }\n        }\n        \n        \n        return c[s][f] = ans%mod;\n        \n    }\n    \n    \n    int countRoutes(vector<int>& a, int s, int e, int f) {\n        int n = a.size();\n        vector<vector<int>> c(n+1,vector<int> (f+1,-1));\n        \n        \n        return solve(a,s,e,f,c);\n        \n    }\n};\n```
['C']