All pastes #835324 Raw Edit

Untitled

public text v1 · immutable
#835324 ·published 2007-12-28 20:36 UTC
rendered paste body
#include "windows.h"
#include "stdio.h"

int ary[] = {1,2,50,20,100,30,1};
int ary_len = sizeof(ary)/ sizeof(int);

bool can_be_done(int current_sum,int current_index,int target_sum)
{
        if (current_sum == target_sum)
        {
                return true;
        }
        else if (current_sum > target_sum)
        {
                return false;
        }
        else
        {
				if (current_index+1 == ary_len)
				{
					return false;
				}
                if (can_be_done(current_sum + ary[current_index+1],current_index+1,target_sum))
                {
					printf("%d ",ary[current_index+1]);
					return true;
                }
                else
                {
                        if(can_be_done(current_sum,current_index+1,target_sum))
                        {
                                //printf("%d ",ary[current_index]);
								return true;
                        }
                        else
                        {
                                return false;
                        }
                }              
        }       
}

void main( int argc, char *argv[ ], char *envp[ ] )
{
	if (can_be_done(0,-1,150))
	{
		printf("done!");
	}
	else
	{
		printf("not done");
	}
}