Simple C++ Solution | Dynamic Programming | Recursion | Memoization
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nint mod=1e9+7;\nlong long hope(int index,int prev,vector<int>&curr,vector<int>&visited,string &s,int &n,vector<vector<long long>>&dp){\n    if(index>=s.length() && curr.size()==n+1)return 1;\n    if(dp[index+1][prev+1]!=-1)return dp[index+1][prev+1];\n    long long ans=0;\n    if(index==-1){\n        for(int i=0;i<=n;i++){\n            curr.push_back(i);\n            visited[i]=-1;\n            ans=(ans%mod+hope(index+1,i,curr,visited,s,n,dp)%mod)%mod;\n            curr.pop_back();\n            visited[i]=0;\n        }\n    }\n    else if(index!=-1){\n        if(s[index]==\'I\'){\n            int previous=prev;\n            for(int i=previous+1;i<=n;i++){\n                if(visited[i]!=-1){\n                    curr.push_back(i);\n            visited[i]=-1;\n            ans=(ans%mod+hope(index+1,i,curr,visited,s,n,dp)%mod)%mod;\n            curr.pop_back();\n            visited[i]=0;\n                }\n            }\n        }\n        else if(s[index]==\'D\'){\n            int previous=prev;\n            for(int i=0;i<previous;i++){\n                if(visited[i]!=-1){\n                    curr.push_back(i);\n            visited[i]=-1;\n            ans=(ans%mod+hope(index+1,i,curr,visited,s,n,dp)%mod)%mod;\n            curr.pop_back();\n            visited[i]=0;\n                }\n            }\n        }\n    }\n    return dp[index+1][prev+1]=ans%mod;\n}\n    int numPermsDISequence(string s) {\n        int n=s.length();\n  vector<int>visited(s.length()+1,0);\n  vector<int>curr;\n  vector<vector<long long>>dp(202,vector<long long>(202,-1));\n  long long fa=hope(-1,-1,curr,visited,s,n,dp)%mod;\n  int answer=fa;\n  return answer;      \n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']