[C++] DP
Code\n\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& nums) {\n        long long mod = 1e9 + 7, ans = 0;\n        int n = nums.size();\n        v
# Code\n```\nclass Solution {\npublic:\n    int countOfPairs(vector<int>& nums) {\n        long long mod = 1e9 + 7, ans = 0;\n        int n = nums.size();\n        vector<vector<long long>> dp(n, vector<long long>(1001, 0));\n        for (int j = 0; j <= nums[0]; j++)\n            dp[0][j] = 1;\n        for (int i = 1; i < n; i++)\n        {\n            long long s = 0, k = 0;\n            for (int j = 0; j <= nums[i]; j++)\n            {\n                while (k <= nums[i - 1] && k <= j && nums[i - 1] - k >= nums[i] - j)\n                {\n                    s = (s + dp[i - 1][k]) % mod;\n                    k++;\n                }\n                dp[i][j] = s;\n            }\n        }\n        for (int j = 0; j <= nums[n - 1]; j++)\n            ans = (ans + dp[n - 1][j]) % mod;\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'C++']