JSFiddle - React, Tailwind, and code Playground

by Yogesh Rathod

HTML

<div id='div1'>

</div>

JavaScript

/*
10 4
2 5 3 6 1

output
2 2 2 2 2
2 2 3 3
2 5 3
2 2 6
5 5
*/
var totalcall = 0;
document.getElementById('div1').innerText = ''
function count(a,m,n){

 // document.getElementById('div1').innerText =  document.getElementById('div1').innerText+'count(a,'+m+','+n+') \r\n';
if(n==0)
 return 1;
 if(n<0)
 return 0;
 if(m <=0 && n >= 1)
 return 0;
 if(m > 0 && n > 0)
  totalcall++;
 return count(a,m-1,n) + count(a,m,n-a[m-1]);
}
var a = [2,5,3,6]
//count(a,3,4)
//alert(totalcall);


function count1( int S[], int m, int n )
{
	var i, j, x, y;

	// We need n+1 rows as the table is consturcted in bottom up manner using 
	// the base case 0 value case (n = 0)
	int table[n+1][m];
	
	// Fill the enteries for 0 value case (n = 0)
	for (i=0; i<m; i++)
		table[0][i] = 1;

	// Fill rest of the table enteries in bottom up manner 
	for (i = 1; i < n+1; i++)
	{
		for (j = 0; j < m; j++)
		{
			// Count of solutions including S[j]
			x = (i-S[j] >= 0)? table[i - S[j]][j]: 0;

			// Count of solutions excluding S[j]
			y = (j >= 1)? table[i][j-1]: 0;

			// total count
			table[i][j] = x + y;
		}
	}
	return table[n][m-1];
}

count1(4,10);
 alert(table.length);
 for(var j1=0;j1< table.length;j1++) {
 document.getElementById('div1').innerText =  document.getElementById('div1').innerText + table[j1];
 }
 
  1 2 3
  0 0 0
  0 0 0
  0 0 0