結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-05-28 03:18:24 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,469 bytes |
| コンパイル時間 | 1,982 ms |
| コンパイル使用メモリ | 108,288 KB |
| 実行使用メモリ | 19,584 KB |
| 最終ジャッジ日時 | 2024-10-07 17:11:36 |
| 合計ジャッジ時間 | 3,510 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 RE * 3 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program
{
public void Proc()
{
Reader.IsDebug = false;
int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
ItemCount = inpt[0];
int inputCount = inpt[1];
for(int i=0; i<inputCount; i++) {
inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
if(!pointDic.ContainsKey(inpt[1])) {
pointDic.Add(inpt[1], new Dictionary<int,long>());
}
pointDic[inpt[1]].Add(inpt[0], inpt[2]);
}
long ans = this.GetAns(0, this.ItemCount);
Console.WriteLine(ans);
}
private int ItemCount = 0;
private Dictionary<int, long> dic = new Dictionary<int, long>();
private long GetAns(int flag, int remain) {
if(dic.ContainsKey(flag)) {
return dic[flag];
}
if(remain == 0) {
return 0;
}
long ans = 0;
for(int i=0; i<ItemCount; i++) {
int key = 1<<i;
if((flag & key) == key) {
continue;
}
long p = 0;
foreach (int tmp in pointDic[i].Keys)
{
int subKey = 1<<tmp;
if((flag & subKey) == subKey) {
p+=pointDic[i][tmp];
}
}
long ret = this.GetAns(flag + key, remain - 1);
ret += p;
ans = Math.Max(ans, ret);
}
dic.Add(flag, ans);
return ans;
}
private Dictionary<int, Dictionary<int, long>> pointDic = new Dictionary<int, Dictionary<int, long>>();
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
4 9
0 1 1
0 2 2
0 3 3
1 2 4
1 3 5
2 3 6
3 2 100
2 1 100
1 0 100
";
private static System.IO.StringReader Sr = null;
public static string ReadLine()
{
if (IsDebug)
{
if (Sr == null)
{
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
}
static void Main()
{
Program prg = new Program();
prg.Proc();
}
}
14番