Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // We need n+1 rows as the table is consturcted in bottom up manner using
  2. // the base case 0 value case (n = 0)
  3. int table[n+1][m];
  4.  
  5. // Fill the enteries for 0 value case (n = 0)
  6. for (i=0; i<m; i++)
  7. table[0][i] = 1;
  8.  
  9. // Fill rest of the table enteries in bottom up manner
  10. for (i = 1; i < n+1; i++)
  11. {
  12. for (j = 0; j < m; j++)
  13. {
  14. // Count of solutions including S[j]
  15. x = (i-S[j] >= 0)? table[i - S[j]][j]: 0;
  16.  
  17. // Count of solutions excluding S[j]
  18. y = (j >= 1)? table[i][j-1]: 0;
  19.  
  20. // total count
  21. table[i][j] = x + y;
  22. }
  23. }
  24. return table[n][m-1];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement