Video Explanation (Intuition with proof of Amorized Time complexity)
Explanation\n\nClick here for the video\n\n# Code\n\nclass Solution {\npublic:\n    static const int N = 2e4;\n    int mod= 1e9+7;\n    int cnt[N+1];\n    int c
# Explanation\n\n[Click here for the video](https://youtu.be/V6AoVVxt18Y)\n\n# Code\n```\nclass Solution {\npublic:\n    static const int N = 2e4;\n    int mod= 1e9+7;\n    int cnt[N+1];\n    int countSubMultisets(vector<int>& a, int l, int r) {\n        int dp[N+1];\n        memset(cnt,0,sizeof(cnt));\n        memset(dp,0,sizeof(dp));\n        \n        int n=a.size();\n        for(int x:a)cnt[x]++;\n        dp[0]=cnt[0]+1;\n        for(int i=1;i<=N;i++)\n        {\n            if(!cnt[i])continue;\n            for(int j=N-i;j>=0;j--)\n            {\n                if(!dp[j])continue;\n                for(int k=1;k<=cnt[i];k++)\n                {\n                    int pos=k*i+j;\n                    if(pos>N)break;\n                    (dp[pos]+=dp[j]);\n                    if(dp[pos]>=mod)dp[pos]-=mod;\n                }\n            }\n        }\n        int ans=0;\n        for(int i=l;i<=r;i++)\n        {\n            ans+=dp[i];\n            if(ans>=mod)ans-=mod;\n        }\n        return ans;\n    }\n};\n```
['C++']