title: Maximize consumption Energy
body: <p>There are three types of foods were provided i.e. meat, cake and pizza 
  and N different stores selling it where, <strong>i can only pick one type of food from
  each store</strong>. Also I can only buy items in A, B and C numbers where 'A' means, Meat from total 'A' number of different stores (see example). My task is
  to consume food, so that i can have maximum amount of energy.
  example,</p>
  
  <pre><code>10            &lt;= number of stores &lt;br&gt;
  5 3 2         &lt;= out of 10 stores I can pick meat from 5 stores only. Similarly,
                   I can pick cake from 3 out of 10 stores...
  56 44 41    1 &lt;= Energy level of meat, cake and pizza - (56, 44, 41) for first store.&lt;br&gt; 
  56 84 45    2
  40 98 49    3
  91 59 73    4
  69 94 42    5
  81 64 80    6
  55 76 26    7
  63 24 22    8
  81 60 44    9
  52 95 11    10
  </code></pre>
  
  <p>So to maximize my energy, I can consume...</p>
  
  <ol>
  <li><p>Meat from store numbers:</p>
  
  <pre><code>[1, 4, 7, 8, 9] =&gt; [56, 91, 55, 63, 81]
  </code></pre></li>
  <li><p>Cake from store numbers:</p>
  
  <pre><code>[3, 5, 10] =&gt; [98, 94, 95]
  </code></pre></li>
  <li><p>Pizza from store numbers:</p>
  
  <pre><code>[2, 6] =&gt; [45, 80]
  </code></pre></li>
  </ol>
  
  <p>This leads me to eventually obtain a maximum energy level of 758.</p>
  
  <hr>
  
  <p>As I am new to dynamic programming, I tried to solve it by generating unique combinations like,</p>
  
  <p><sub>10</sub>C<sub>5</sub> * <sub>(10-5)</sub>C<sub>3</sub> * <sub>(10-5-3)</sub>C<sub>2</sub> = 2520</p>
  
  <p>Here is my code,</p>
  
  <pre class="lang-py prettyprint-override"><code>nStores = 10
  a, b, c = 5, 3, 2
  matrix = [
      [56,44,41],
      [56,84,45],
      [40,98,49],
      [91,59,73],
      [69,94,42],
      [81,64,80],
      [55,76,26],
      [63,24,22],
      [81,60,44],
      [52,95,11]
  ]
  
  count = a + b + c
  data = []
  allOverCount = [i for i in range(count)]
  def genCombination(offset, depth, passedData, reductionLevel = 3):
      if (depth == 0):
          first = set(data)
          if reductionLevel ==  3:
              return genCombination(0,b,[i for i in allOverCount if i not in first], reductionLevel=2)
          elif reductionLevel ==  2:
              return genCombination(0,c,[i for i in allOverCount if i not in first], reductionLevel=1)
          elif reductionLevel == 1:
              xAns = 0
              for i in range(len(data)):
                  if i &lt; a:
                      xAns += matrix[data[i]][0]
                  elif i &lt; a + b:
                      xAns += matrix[data[i]][1]
                  else:
                      xAns += matrix[data[i]][2]
              return xAns
      oneData = 0
      for i in range(offset, len(passedData) - depth + 1 ):
          data.append(passedData[i])
          oneData = max(oneData, genCombination(i+1, depth-1, passedData, reductionLevel))
          del data[-1]
      return oneData
  passedData = [i for i in range(count)]
  finalOutput = genCombination(0,a,passedData)
  print(finalOutput)
  </code></pre>
  
  <p>I know this is not the right way to do it. How can I optimize it? </p>