C++ prefix sum + dp
\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& nums) {\n        int count[1001][2001] = {0};\n        for (int i = 0; i < 1001; ++i) {\n        
```\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& nums) {\n        int count[1001][2001] = {0};\n        for (int i = 0; i < 1001; ++i) {\n            count[i][0] = 1;\n        }\n        \n        int mod = 1e9 + 7;\n        for (int i = 1; i < nums.size(); ++i) {\n            for (int j = 1; j < 1001; ++j) {\n                count[j][i - 1] = (count[j][i - 1] + count[j - 1][i - 1]) % mod;\n            }\n            \n            for (int a = max(0, nums[i] - nums[i - 1]); a <= nums[i]; ++a) {\n                count[a][i] = (count[min(a, nums[i - 1] - nums[i] + a)][i - 1] + count[a][i]) % mod;\n            }\n        }\n        \n        int res = 0;\n        for (int i = 0; i <= nums.back(); ++i) {\n            res = (res + count[i][nums.size() - 1]) % mod;\n        }\n        return res;\n    }\n};\n```
[]