結果

問題 No.505 カードの数式2
ユーザー akitsu818
提出日時 2017-04-30 18:08:55
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 642 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 74,656 KB
実行使用メモリ 55,968 KB
最終ジャッジ日時 2024-09-13 23:52:08
合計ジャッジ時間 8,515 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	static int target;
	public static void main(String argas[]){

		Scanner cin = new Scanner(System.in);

		target = cin.nextInt();
		int list[] = new int[target];

		for(int i=0;i<target;i++){
			list[i] = cin.nextInt();
		}
		cin.close();
		System.out.println(dfs(0,0,list));
	}

	static int dfs(int count,int sum,int array[]){
		if(count==target-1){
			return Math.max(sum*array[count], Math.max(sum+array[count],sum-array[count]));
		}else{
			return Math.max(dfs(count+1,sum*array[count],array), Math.max(dfs(count+1,sum+array[count],array), dfs(count+1,sum-array[count],array)));
		}
	}

}
0