結果
| 問題 |
No.324 落ちてた閉路グラフ
|
| ユーザー |
kuuso1
|
| 提出日時 | 2015-12-17 23:35:30 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,734 bytes |
| コンパイル時間 | 2,682 ms |
| コンパイル使用メモリ | 107,264 KB |
| 実行使用メモリ | 445,824 KB |
| 最終ジャッジ日時 | 2024-09-16 07:45:05 |
| 合計ジャッジ時間 | 12,117 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 RE * 5 |
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
int[][][] dp=new int[N+1][][];
for(int i=0;i<=N;i++){
dp[i]=new int[M+1][];
for(int j=0;j<=M;j++){
dp[i][j]=new int[2];
dp[i][j][0]=dp[i][j][1]=-Inf;
}
}
//1つめを取った場合
dp[0][1][1]=0;
for(int i=0;i<N-1;i++){
for(int j=0;j<=Math.Min(M,i+1);j++){
dp[i+1][j][0]=Math.Max(dp[i+1][j][0],dp[i][j][0]);
if(j<M)dp[i+1][j+1][1]=Math.Max(dp[i+1][j+1][1],dp[i][j][0]);
dp[i+1][j][0]=Math.Max(dp[i+1][j][0],dp[i][j][1]);
if(j<M)dp[i+1][j+1][1]=Math.Max(dp[i+1][j+1][1],dp[i][j][1]+A[i]);
}
}
for(int j=0;j<=M;j++){
dp[N][j][0]=Math.Max(dp[N][j][0],dp[N-1][j][0]);
dp[N][j][1]=Math.Max(dp[N][j][1],dp[N-1][j][1]+A[N-1]);
}
int ans1=Math.Max(dp[N][M][0],dp[N][M][1]);
//1つめを取らなかった場合
for(int i=0;i<=N;i++){
for(int j=0;j<=M;j++){
dp[i][j][0]=dp[i][j][1]=-Inf;
}
}
dp[0][0][0]=0;
for(int i=0;i<N-1;i++){
for(int j=0;j<=Math.Min(M,i+1);j++){
dp[i+1][j][0]=Math.Max(dp[i+1][j][0],dp[i][j][0]);
if(j<M)dp[i+1][j+1][1]=Math.Max(dp[i+1][j+1][1],dp[i][j][0]);
dp[i+1][j][0]=Math.Max(dp[i+1][j][0],dp[i][j][1]);
if(j<M)dp[i+1][j+1][1]=Math.Max(dp[i+1][j+1][1],dp[i][j][1]+A[i]);
}
}
for(int j=0;j<=M;j++){
dp[N][j][0]=Math.Max(dp[N][j][0],dp[N-1][j][0]);
dp[N][j][1]=Math.Max(dp[N][j][1],dp[N-1][j][1]);
}
int ans0=Math.Max(dp[N][M][0],dp[N][M][1]);
Console.WriteLine(Math.Max(ans0,ans1));
}
int N,M;
int[] A;
static int Inf=(int)1e9;
public Sol(){
var d=ria();
N=d[0];M=d[1];
A=ria();
}
void dbg(int[][][] dp){
for(int m=M;m>=0;m--){
for(int n=0;n<=N;n++){
Console.Write("{0} ",dp[n][m][0]==-Inf?"X":dp[n][m][0].ToString());
}
Console.WriteLine();
for(int n=0;n<=N;n++){
Console.Write("{0} ",dp[n][m][1]==-Inf?"X":dp[n][m][1].ToString());
}
Console.WriteLine();
Console.WriteLine();
}Console.WriteLine();
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(){return Console.ReadLine().Split(' ');}
static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
kuuso1