DP with tabulation |  C++  |  O(n*1000)  |  Prefix Sum
\n# Complexity\n- Time complexity:  O ( N * 1000 )\n- Space complexity: O ( N * 1000 )\n\n# Code\n\n#define mod 1000000007\nclass Solution {\npublic:\n    int c
\n# Complexity\n- Time complexity:  O ( N * 1000 )\n- Space complexity: O ( N * 1000 )\n\n# Code\n```\n#define mod 1000000007\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> dp(1001,0);\n        for(int i = 0; i<=nums[0]; i++){\n            dp[i] = 1;\n        }\n        for(int i = 1; i<=1000; i++){\n            dp[i] += dp[i-1];\n            dp[i] %= mod;\n        }\n        for(int i = 2; i<=n; i++){\n            vector<int> curr(1001,0);\n            int d = nums[i-1]-nums[i-2];\n            for(int j = 0; j<=1000; j++){\n                int l = max(j,j-d);\n                l = min(1001,l);\n                curr[j] = dp[1000];\n                if(l != 0) {\n                    curr[j] -= dp[l-1];\n                    if(curr[j] < 0) curr[j] += mod;\n                }\n                curr[j] %= mod;\n            }\n            for(int j = 1; j<=1000; j++){\n                curr[j] = (curr[j] + curr[j-1])%mod;\n            }\n            dp = curr;\n        }\n        int ans = dp[1000]%mod;\n        return ans;\n    }\n};\n```
['C++']