Hi shubham,
you're problem is the limitation of the stack size. You create some copies
of your vector's (e.g. for each recursive call of "check" or "total"), the
vector's are copied (you do NOT pass references). All those temporary
vectors are generated on the stack ==> you're out of stack space and thus
get a segfault. However, on my machine, the problem does NOT appear in
push_back, but during the copy-operations when the vector's are copied for
call's to check/solve.
Here is the code:
>
> int check(vector<int>total,vector<bool>arr)
> {
> }
>
> int solve(vector<int>total,vector<bool>arr,int m,int n)
> {
> int val=check(total,arr);
> if(n<arr.size())
> {
> val=solve(total,arr,m,n+1);
> }
> else
> {
> val=solve(total,arr,m+1,0);
> }
> }
> return 0;
> }
> int main()
> {
> val=solve(total,arr,0,1);
> }
>
(I've removed the code except the "recursive" parts showing where you
allocate stack space...
Solutions:
- increase stackspace (e.g. on linux by "ulimit")
- make less recursions
- pass references wherever possible
- allocate the structures on the heap
:-)
Axel
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.