結果

問題 No.4 おもりと天秤
ユーザー いろどりいろどり
提出日時 2015-12-13 01:18:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 577 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 144,372 KB
実行使用メモリ 11,464 KB
最終ジャッジ日時 2023-10-13 14:11:31
合計ジャッジ時間 8,773 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,216 KB
testcase_01 AC 4 ms
7,192 KB
testcase_02 AC 4 ms
7,316 KB
testcase_03 AC 4 ms
7,360 KB
testcase_04 AC 4 ms
7,212 KB
testcase_05 TLE -
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 #

//yukicoder 4
#include <bits/stdc++.h>
using namespace std;

int n, weight;
int w[100];
int dp[101][10001];

int dfs(int i, int sum) {
	if(dp[i][sum] >= 0) return dp[i][sum];
	if(i == n) return (double)sum == ((double)weight / 2);
	if(dfs(i + 1, sum)) return 1;
	if(dfs(i + 1, sum + w[i])) return 1;
	return 0;
}

int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> w[i];
		weight += w[i];
	}
	for(int i = 0; i < 101; i++) {
		for(int j = 0; j < 10001; j++) dp[i][j] = -1;
	}
	if(dfs(0, 0)) cout << "possible";
	else cout << "impossible";
	cout << endl;
	return 0;
}
0