結果

問題 No.4 おもりと天秤
ユーザー prog470prog470
提出日時 2016-05-16 16:24:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 622 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 159,416 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2024-04-15 22:27:08
合計ジャッジ時間 7,842 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 OLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int a = 0, t = 0, tw;
bool dp[110][2];
int n,w[110];

//zenntannsaku
bool dfs(int d, int f, int sum){
	
	if(d == n-1){
		cout<<"sum : "<<sum<<endl;
		return (sum == tw);
	}	

	return (dfs(d+1, 0, sum+=w[d+1]*0) || dfs(d+1, 1, sum+=w[d+1]*1));

}

int main(){
	cin>>n;

	for(int i=0; i<n; i++){
		cin>>w[i];
		t += w[i];
	}

	tw = t/2;

	for(int i=0; i<n; i++){
		dp[i][0] = dp[i][1] = -1; 
	}

	if(((t%2==0) && dfs(0,0,0)) || ((t%2==0) && dfs(0,1,w[0]))){
		cout<<"possible"<<endl;
	}else{
		cout<<"impossible"<<endl;
	}

	return 0;
}
0