vendredi 12 juin 2015

Runtime error in c++(ideone.com)

I have written a code for selecting k elements in a subset from n elements in a set,and then those subsets need to be summed up individually and the fibonacci value of their sums need to be added up.like for n=4 k=3 and S={1,2,3,4} the subsets will be {1,2,3} and {1,2,4} and {1,3,4} and {2,3,4} therefore answer will be fibonacci[6]+fibonacci[7]+fibonacci[8]+fibonacci[9]. My code is compiling on my computer but giving runtime error on ideone.com, I am unable to understand why???can somebody please help me out!!

 #include<algorithm>
#include<iostream>
#include<string>
using namespace std;
long long int arr[50009]={0};
unsigned long long int fibo[50009]={0};
unsigned long long int sum=0,sumo=0;
void fib(int j)
{sumo+=fibo[j];
} 
void comb(int N, int K,long long int arr[])
{ int sum=0;
    string bitmask(K, 1);
    bitmask.resize(N, 0);
    do 
    {sum=0;
        for (int i = 0; i < N; ++i)
        {if (bitmask[i]) 
            sum+=arr[i];
        }
        fib(sum);
    } 
    while 
    (prev_permutation(bitmask.begin(), bitmask.end()));


}
int main()
{int i,n,k;
   cin>>n>>k;
   fibo[1]=1;
   fibo[2]=1;
   for(i=3;i<50000;i++)
       {fibo[i]=fibo[i-1]+fibo[i-2];
       }
   for(i=0;i<n;i++)
       {cin>>arr[i];
       }
   comb(n,k,arr);
   cout<<sumo<<endl;

return 0;
}

Aucun commentaire:

Enregistrer un commentaire