I am given a number n and a number b.
i have n products and for each product a grade like 'e' for electronics or 'f' for food.
I must show only the products with a number of grades smaller or equal to my given b
It's like:
n=4
b=1
grades: 'e' 'f' 'f' 'e'
The result will be:
1
1 2
1 3
2
2 4
3
3 4
4

Please help :D Or ask for more info's.
I started with a basic subset program using backtracking:

#include<iostream.h>
#include<fstream.h>
ifstream f("magazin.in");
ofstream g("magazin.out");
int st[100],n,b;
int gr[100];
int valid(int p)
{
        // here comes a condition    
    return 1;
}
void back(int k)
{
    int i,j;
    for(i=st[k-1]+1;i<=n;i++)
    {
        st[k]=i;
        if(valid(k)==1)

        {
            for(j=1;j<=k;j++)
                g<<st[j]<<" ";
            g<<endl;
        }
                back(k+1);
    }
}
int main()
{
    f>>n;
    f>>b;
    for(int i=1;i<=n;i++)
        f>>gr[i];

    back(1);
    return 0;
}

I think i solved it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.