Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Collection;
- import java.util.Arrays;
- import java.util.Scanner;
- public class MAin {
- private static int n;
- private static int[] niza;
- static int rec(int x) {
- if(x == 0) {
- return 0;
- }
- int result = (int) 2e9;
- for(int i =0 ; i < n; i++) {
- if(x - niza[i] >= 0) {
- result = Math.min(result, rec(x - niza[i]) + 1);
- }
- }
- return result;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- n = sc.nextInt();
- niza = new int [n];
- for(int i = 0; i < n; i++) {
- niza[i] = sc.nextInt();
- }
- int suma = sc.nextInt();
- System.out.println(rec(suma));
- }
- }
- // 50- 10 - 20 = 20
- // 60 + 100 +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement