Posts

Showing posts with the label Solution

Beautiful Graph Problems

Cycle in a 2D graph with DFS Problem Link :  Fox And Two Dots Solution Idea : This problem can be solved using DFS. You can Check my  Solution  . Coloring a graph  Problem Link :  Coloring a Tree Solution Idea : Using DFS we can color a node and its subtree. We are coloring only subtrees. so we can't visit upwards of a tree while coloring. That's why we are using directed graph. if a tree is already colored in it's required color, we don't need to color it anymore. You can Check my  Solution . Also solved  Customized Chess Board  ( brute force approach )

Marbels (Codeshef)

Problem link :  MARBLES In order to solve this problem we need to know basic permutation and combination. We can address this problem with the tag "Selection With Repetition" . If we have n type of object or n objects and we have to choose k objects from these where each object can be choosen multiple times, then number of ways we can do it is  (n+k-1) C (k). Let's come to our problem. we have K type of objects and we have to choose N objects from them. So, now we can convert the given formula into (K+N-1) C (N). Suppose , we have 30 objects to choose and we have 7 types of objects. This formula will give us (36)C(30) = 1947792. Which is much much greater that the required answer. This happens because we have calculated all the possibilities without filtering those possibilities where we haven't taken at least one from each types (which is a key condition) . Let's assume another example - we have two letters A , B and we have to choose 3 letters each ti...