Skip to content

Instantly share code, notes, and snippets.

@pureexe
Created August 21, 2013 12:36
Show Gist options
  • Select an option

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

Select an option

Save pureexe/6293914 to your computer and use it in GitHub Desktop.
rewrite SU40_P7
#include<iostream>
using namespace std;
int row,money,tab[21][21],big=-1;
int gen(int n,int value)
{
int i;
if(value>money)
{
return 0;
}
if(n<=row)
for(i=1;i<=tab[n][0];i++)
{
gen(n+1,value+tab[n][i]);
}
if(value>big&&n>=row)
big=value;
}
int main()
{
cin >> money >> row;
int i,j;
for(i=0;i<row;i++)
{
cin >> tab[i][0];
for(j=1;j<=tab[i][0];j++)
{
cin >> tab[i][j];
}
}
gen(0,0);
if(big==-1)
cout << "No Solution";
else
cout << big;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment