結果

問題 No.286 Modulo Discount Store
ユーザー mban
提出日時 2017-04-28 16:21:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 3,071 ms
コンパイル使用メモリ 111,860 KB
実行使用メモリ 27,200 KB
最終ジャッジ日時 2024-09-13 17:48:44
合計ジャッジ時間 3,341 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

public class Program
{
    static private int N;
    static private int[] M;
    static private void Scan()
    {
        N = int.Parse(Console.ReadLine());
        M = new int[N];
        for (int i = 0; i < N; i++)
        {
            M[i] = int.Parse(Console.ReadLine());
        }
    }

    static public void Main(string[] args)
    {
        Scan();

        int[] dp = (new int[1 << N]).Select(i => int.MaxValue).ToArray();
        int[] teika = (new int[1 << N]).Select(i => int.MaxValue).ToArray();
        dp[0] = 0;
        teika[0] = 0;

        for (int i = 0; i < 1 << N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                int k = 1 << j;
                if ((i & k) > 0) continue;

                teika[i + k] = teika[i] + M[j];
                dp[i + k] = Math.Min(dp[i + k], dp[i] + Math.Max(0, M[j] - teika[i] % 1000));
            }
        }

        Console.WriteLine(dp[(1 << N) - 1]);
    }

}

0