Created
August 5, 2013 09:23
-
-
Save pureexe/6154581 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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