結果

問題 No.324 落ちてた閉路グラフ
ユーザー pekempey
提出日時 2015-12-17 01:20:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,531 ms / 5,000 ms
コード長 1,170 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 112,596 KB
実行使用メモリ 162,432 KB
最終ジャッジ日時 2024-11-15 19:27:13
合計ジャッジ時間 34,090 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			new Program().Solve();
		}

		void Solve()
		{
			string[] tmp = Console.ReadLine().Split();
			int n = int.Parse(tmp[0]);
			int m = int.Parse(tmp[1]);
			int[] w = Console.ReadLine().Split().Select(int.Parse).ToArray();

			const int Inf = (int)1e9;

			var dp = new int[3030, 3030, 2, 2];
			for (int i = 0; i < 3030; i++)
			for (int j = 0; j < 3030; j++)
			for (int k = 0; k < 2; k++)
			for (int l = 0; l < 2; l++)
				dp[i, j, k, l] = -Inf;

			dp[0, 0, 0, 0] = dp[0, 1, 1, 1] = 0;

			for (int i = 1; i < n; i++)
			for (int j = 0; j <= m; j++)
			for (int k = 0; k <= 1; k++)
			for (int l = 0; l <= 1; l++)
			{
				dp[i, j, 0, l] = Math.Max(dp[i, j, 0, l], dp[i - 1, j, k, l]);
				dp[i, j + 1, 1, l] = Math.Max(dp[i, j + 1, 1, l], dp[i - 1, j, k, l] + w[i] * k);
			}
			int ans = -Inf;
			for (int k = 0; k <= 1; k++)
				for (int l = 0; l <= 1; l++)
					ans = Math.Max(ans, dp[n - 1, m, k, l] + k * l * w[0]);
			Console.WriteLine(ans);
		}
	}
}
0