Exemplo n.º 1
0
int main( int argc, char **argv )
{
	/* perform a simple parameter check */
	if( argc != 3 )
		exit( EXIT_FAILURE );

	/* initialation */
	int p[] = { 0, 1, 5, 8, 9, 10, 17, 17, 20, 24, 30 };
	int rod_length = atoi( argv[2] );
	/* Use proceed to store the solution value, s to store the solution */
	int proceed = 0;
	int *s = (int *)malloc( sizeof(int) * ( rod_length +1 ) );

	/* calculate the solution */
	switch( argv[1][1] ){
	case 'r':
		proceed = cut_rod( p, rod_length, s );
		break;
	case 'm':
		proceed = memoized_cut_rod( p, rod_length, s );
		break;
	case 'b':
		proceed = bottom_up_cut_rod( p, rod_length, s );
		break;
	default:
		exit( EXIT_FAILURE );
	}

	/* print the solution */
	print_cut_rod_solution( rod_length, proceed, s );
	return 0;
}
Exemplo n.º 2
0
int main(void)
{
    int len = 8;
    int revenue[40];
    int s[40];
    int r;
    int i;
    for(i=0;i<40;i++){
        revenue[i] = -1;
        s[i] = i;
    }
    r = cut_rod_v4 (price, revenue, s, len);
    printf("The max revenue of a %d meters rod is: %d\n", len, r);
    print_cut_rod_solution(s, len);
}