結果

問題 No.247 線形計画問題もどき
ユーザー kano_town
提出日時 2015-07-18 00:19:49
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 3,170 ms
コンパイル使用メモリ 75,524 KB
実行使用メモリ 61,908 KB
最終ジャッジ日時 2024-07-08 09:51:29
合計ジャッジ時間 8,827 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 WA * 1
other AC * 13 WA * 2 TLE * 1 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Yukicoder247 {

    int now;
    static boolean ok = false;
    static int min = 100000000;
    static int[] a;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt();
        int n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        // ゴリ押し
        gorigori(n - 1, c, 0);
        System.out.println(min);
    }

    public static void gorigori(int now, int nokori, int num) {
        if ( now < 0) return;
        if (nokori % a[now] == 0) {
            min = Math.min(num + nokori / a[now], min);
            ok = true;
            return;
        }
        for (int i = nokori / a[now]; i >= 0; i--) {
            gorigori(now - 1, nokori - i * a[now], num + i);
        }
    }
}
0