TYPE of kbag problem (sum of subset problem)
vector<vector<int>>sum(int a[],int  sum,int n)
{
int i=0,j=0;
for(i=0;i<(n+1);i++)
{
   for(j=0;j<(sum+1);j++)
   {
   if(i==0)
   t[i][j]=False;
   if(j==0)
   t[i][j]=True
    }
}
for(i=0;i<(n+1);i++)
{
   for(j=0;j<(sum+1);j++)
   {
       if(a[i-1]<j)
	   {
	   t[i][j]=(t[i][j-a[i-1]] || t[i-1][j]);
	   }
	   else
	   {
	   t[i][j]=t[i-1][j];
	   }
    }
}
return t;
}
Comments (0)