Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  gera01
Language: C/C++
Code:
#include<bits/stdc++.h>
using namespace std;

int arr[]={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};
int r=18;

int rec(int index,int cnt,vector<int> v)
{
    if(cnt==r)
    {
        cout<<"IN ";
        for(int i=0;i<v.size();i++)
        {
            cout<<v[i]<<" ";
        }
        cout<<endl;
        return 1;
    }
    if(index>=25)
    {
        return 0;
    }

    int a;

    vector<int> temp;
    temp=v;
    temp.push_back(arr[index]);
    a=rec(index+1,cnt+1,temp)+rec(index+1,cnt,v);

    return a;
}

int main()
{
    vector<int> v;
    int cnt=0;
    int a=rec(0,cnt,v);
    cout<<"a="<<a<<endl;
    return 0;
}
Comments: