greedy algorithm with all posible combinations of a given number

I need help with solving this problem. I can use numbers 20,10,5,2 or 1 and have to display all posible combinations.
input: 11
output:
10,1
5,5,1
5,2,2,2
5,2,2,1,1
5,2,1,1,1,1
5,1,1,1,1,1,1
2,2,2,2,2,1
2,2,2,2,1,1,1
2,2,2,1,1,1,1,1
2,2,1,1,1,1,1,1,1
2,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1
Last edited on
i m a newbie so i still lack knowlage to understand what the advanced programs say. is there mybe a version of program that only involves "for" and "if" functions ?
is there mybe a version of program that only involves "for" and "if" functions ?

Neither "for" nor "if" are functions and I doubt a version using only "for" and "if" would be readable to anyone. The first link describes an algorithm in pseudo-code. Implement the algorithm with whatever constructs you are familiar with.
can you mybe work out something with this ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>

using namespace std;

int main()
{
const int dvajset=20;
const int deset=10;
const int pet=5;
const int dva=2;
const int ena=1;
int vracilo;
cout << "vracilo: \n";
cin >> vracilo;

    for(int b=0;b<vracilo/ena;b++){
    for(int a=0;a<vracilo/dva;a++){
    for(int x=0;x<vracilo/pet;x++){
    for(int y=0;y<vracilo/deset;y++){
    for(int z=0;z<vracilo/dvajset;z++){
                            
    cout<<" 20eur.";
            }
    cout<<" 10eur.";
            }
    cout << " 5eur.";
            }
    cout<<" 2eur.";
            }
    cout<<" 1eur.";
            }

}
Last edited on
Topic archived. No new replies allowed.