Skip to content

Instantly share code, notes, and snippets.

@pureexe
Created August 5, 2013 09:23
Show Gist options
  • Select an option

  • Save pureexe/6154581 to your computer and use it in GitHub Desktop.

Select an option

Save pureexe/6154581 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<algorithm>
using namespace std;
int tab[20][20],c[20],M,u=0,n;
int gen(int r,int v)
{
if(r>=n)
{
if(v>u&&v<=M)
{
u=v;
}
return 0;
}
int i;
for(i=0;i<c[r];i++)
{
gen(r+1,v+tab[r][i]);
}
}
int main()
{
int i,j;
cin >>M>>n;
for(i=0;i<n;i++)
{
cin >> c[i];
for(j=0;j<c[i];j++)
{
cin >> tab[i][j];
}
}
gen(0,0);
if(u==0)
cout << "No Solution";
else
cout << u;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment