Javascript - dp
\n\nvar countOfPairs = function(nums) {\n    const n = nums.length; \n    const dp = Array(n+1).fill(0).map(() => Array(1001).fill(0)); \n    dp[n].fill(1); \n 
\n```\nvar countOfPairs = function(nums) {\n    const n = nums.length; \n    const dp = Array(n+1).fill(0).map(() => Array(1001).fill(0)); \n    dp[n].fill(1); \n    for (let i = n-1; i >= 0; --i) {\n        let diff = 0; \n        if (i) diff = Math.max(0, nums[i] - nums[i-1]); \n        for (let j = 1000; j >= 0; --j) {\n            if (j+1 <= 1000) dp[i][j] = dp[i][j+1]; \n            if (j+diff <= nums[i])\n                dp[i][j] = (dp[i][j] + dp[i+1][j+diff]) % 1_000_000_007; \n        }\n    }\n    return dp[0][0]; \n};\n```
['JavaScript']