From 12ac1a81fd4728031cf9151196999edc1cadde7d Mon Sep 17 00:00:00 2001 From: chayan das Date: Sun, 18 May 2025 23:45:54 +0530 Subject: [PATCH] Create 1931. Painting a Grid With Three Different Colors --- ...ainting a Grid With Three Different Colors | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 1931. Painting a Grid With Three Different Colors 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; + + } + +};