package aa;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Q1 {
/* Retorna o melhor preço obtido para uma vara de comprimento
N e preço [] como preços de diferentes peças */
static int cutRod(int price[], int n)
<p> {
if (n <= 0)
return 0;
int max_val = Integer.MIN_VALUE;
// Recursivamente cortar a haste em diferentes peças e
// Comparar diferentes configurações
for (int i = 0; i<n; i++)
max_val = Math.max(max_val,
price[i] + cutRod(price, n-i-1));
return max_val;
}
/* Programa para testar funções acima
*/
public static void main(String[] args) throws FileNotFoundException {
int arr[] = new int[] {4, 2, 3, 4, 5, 6, 7};
int size = arr.length;
System.out.println("O Valor Máximo Obtido é: "+
cutRod(arr, size));
}
}
Qual a dificuldade?