結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
doyazaki012
|
| 提出日時 | 2015-05-27 23:43:23 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,133 bytes |
| コンパイル時間 | 2,028 ms |
| コンパイル使用メモリ | 78,988 KB |
| 実行使用メモリ | 78,240 KB |
| 最終ジャッジ日時 | 2024-07-06 11:58:12 |
| 合計ジャッジ時間 | 7,796 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 WA * 12 RE * 9 |
ソースコード
import java.util.*;
//memo
class Yuki4_2{
public static final int MAX_N = 100;
public static final int MAX_W = 1100;
public static boolean[][] dpChecker = new boolean[MAX_N+1][MAX_W+1];
public static int[][] dpMemo = new int[MAX_N+1][MAX_W+1];
public static int[] w = new int[MAX_N+1];
static int myDP(int i,int j){
System.out.println(i+" "+j);
if(dpChecker[i][j] == true) {return dpMemo[i][j];}
int res;
if(i==MAX_N){res = 0;}
else if(j < w[i]){res = myDP(i+1,j);}
else{
if(myDP(i+1,j-w[i])+w[i] < myDP(i+1,j)){
res = myDP(i+1,j);
}else{
res = myDP(i+1,j-w[i])+w[i];
}
}
dpChecker[i][j] = true;
dpMemo[i][j] = res;
return res;
}
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
int n = stdIn.nextInt();
int sumW = 0;
for(int i=0;i<n;i++){
w[i] = stdIn.nextInt();
sumW += w[i];
}
if(sumW%2 == 0){
int answer = myDP(0,sumW/2);
if(answer == sumW/2){
System.out.println("possible");
}else{
//System.out.println(answer);
System.out.println("impossible");
}
}else{
System.out.println("impossible");
}
}
}
doyazaki012