結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2014-11-11 12:44:12 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 891 bytes |
| コンパイル時間 | 2,383 ms |
| コンパイル使用メモリ | 78,348 KB |
| 実行使用メモリ | 61,688 KB |
| 最終ジャッジ日時 | 2024-12-31 09:38:04 |
| 合計ジャッジ時間 | 5,513 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 2 |
ソースコード
import java.util.*;
public class Main {
static int N;
static int T;
static int[] a;
static boolean[][] dp;
static void dfs(int now,int sum,ArrayList<Character> result ){
if(now==N-1){
if(sum==T){
for(char g:result){
System.out.print(g);
}
System.exit(0);
}
return;
}
if(sum>=T) return;
if(dp[now][sum]) return;
result.add('+');
dfs(now+1,sum+a[now+1],result);
dp[now][sum] =true;
result.remove(result.size()-1);
result.add('*');
dfs(now+1,sum*a[now+1],result);
dp[now][sum]=true;
result.remove(result.size()-1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
T = sc.nextInt();
a = new int[N];
for(int i=0;i<N;i++){
a[i] = sc.nextInt();
}
dp=new boolean[51][100001];
dfs(0,a[0],new ArrayList<Character>());
}
}
kou6839