diff --git a/1931. Painting a Grid With Three Different Colors b/1931. Painting a Grid With Three Different Colors new file mode 100644 index 0000000..cb70fad --- /dev/null +++ b/1931. Painting a Grid With Three Different Colors @@ -0,0 +1,59 @@ +class Solution { +public: + int md = 1e9+7; + bool isValid(int mask,int m){ + int prev = -1; + for(int i=0;i validMasks; + for(int i=0;i> adj; + for(auto a : validMasks){ + for(auto b : validMasks){ + if(isCompatible(a,b,m)){ + adj[a].push_back(b); + } + } + } + map dp; + for(auto mask : validMasks){ + dp[mask] = 1; + } + + for(int i=1;i updatedDP; + for(auto &[mask,count] : dp){ + for(auto nei : adj[mask]){ + updatedDP[nei] = (updatedDP[nei] + count)%md; + } + } + dp = updatedDP; + } + + int ans = 0; + for(auto &[x,val] : dp) ans = (ans + val)%md; + + return ans; + + } + +};