結果

問題 No.247 線形計画問題もどき
ユーザー sekiya9311
提出日時 2016-10-25 22:24:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 107,008 KB
実行使用メモリ 17,956 KB
最終ジャッジ日時 2024-07-07 11:52:22
合計ジャッジ時間 2,755 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Template
{
static Scanner sc;
public static void Main(string[] args)
{
const int INF = (int)1e9;
sc = new Scanner();
int C = sc.nextInt();
int N = sc.nextInt();
int[] a = sc.nextIntArray();
Array.Sort(a);
Array.Reverse(a);
int[] dp = new int[C * 2];
for (int i = 0; i < dp.Length; i++)
{
dp[i] = INF;
}
//dp[i] : f(...) = ix
dp[0] = 0;
//while (true)
{
for (int i = 0; i < C; i++)
{
foreach (var el in a)
{
if (i + el <= C && dp[i] != INF)
{
dp[i + el] = Math.Min(dp[i + el], dp[i] + 1);
}
}
}
}
if (dp[C] == INF)
{
dp[C] = -1;
}
Console.WriteLine(dp[C]);
}
}
public class Scanner
{
public Scanner() { }
public string next()
{
return Console.ReadLine();
}
public int nextInt()
{
return int.Parse(next());
}
public double nextDouble()
{
return double.Parse(next());
}
public long nextLong()
{
return long.Parse(next());
}
public string[] nextArray()
{
return next().Split(' ');
}
public int[] nextIntArray()
{
return Array.ConvertAll(nextArray(), e => int.Parse(e));
}
public long[] nextLongArray()
{
return Array.ConvertAll(nextArray(), e => long.Parse(e));
}
public double[] nextDoubleArray()
{
return Array.ConvertAll(nextArray(), e => double.Parse(e));
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0