[C++] Easy to Understand DP solution | Clean and consize
Please upvote if it helps!\n\n#define mp make_pair\nclass Solution {\n    map<pair<TreeNode*,int>, int> m;\npublic:\n    int func(TreeNode* root, int f)\n    {\
Please upvote if it helps!\n```\n#define mp make_pair\nclass Solution {\n    map<pair<TreeNode*,int>, int> m;\npublic:\n    int func(TreeNode* root, int f)\n    {\n        if(!root)\n            return 0;\n        \n        if(m[mp(root,f)]!=0)\n            return m[mp(root,f)];\n        \n        int ans = func(root->left, 0) + func(root->right, 0);\n        if(f==0)\n        {\n            ans = max(ans, root->val+func(root->left,1) + func(root->right,1));\n        }\n        return m[mp(root,f)] = ans;\n    }\n    \n    int rob(TreeNode* root) {\n        if(!root)\n            return 0;\n        int ans = func(root,0);\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']