[Python3] dp
\n\nclass Solution:\n    def countOfPairs(self, nums: List[int]) -> int:\n        n = len(nums)\n        dp = [[0]*1001 for _ in range(n+1)]\n        dp[n] = [1
\n```\nclass Solution:\n    def countOfPairs(self, nums: List[int]) -> int:\n        n = len(nums)\n        dp = [[0]*1001 for _ in range(n+1)]\n        dp[n] = [1]*1001\n        for i in range(n-1, -1, -1): \n            diff = 0 \n            if i: diff = max(0, nums[i] - nums[i-1])\n            for j in range(1000, -1, -1): \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        return dp[0][0]\n```
['Python3']