結果

問題 No.4 おもりと天秤
ユーザー keikei
提出日時 2016-08-11 17:41:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,037 bytes
コンパイル時間 625 ms
コンパイル使用メモリ 66,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 01:28:03
合計ジャッジ時間 1,405 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
	/* i番目に合計値m  存在する ⇒ true  存在しない ⇒ bool
	   i:考慮した個数/ m:合計値
		dp[i][m] = {dp[i - 1][m]      ,     dp[i - 1][m - w[i]]} どちらかがtrue ⇒true
	 i番目に合計値m    i番目を値を考慮       i番目の値を考慮
	*/
	int num;
	int w[101];
	bool dp[101][10001] = { false };
	int sum = 0;
	int bal_sum = 0;
	cin >> num;
	for (int i = 0; i < num;i++) {
		cin >> w[i];
		sum += w[i];
		dp[0][w[i]] = true;
	}

	if (sum % 2 == 1) { cout << "impossible" << endl; return 0; }
	sum /= 2;	
	for (int i = 1;i < num;i++) {
		for (int m = 0; m < 10001; m++) {
			if (m - w[i] <= 0) { dp[i][m] = dp[i - 1][m]; continue; }
			
			if (dp[i - 1][m] == true || dp[i - 1][m - w[i]] == true) {
				dp[i][m] = true;
			}
			dp[i][m] = false;
		}
	}
	if (dp[num - 1][sum] == true) { cout << "possible" << endl; }
	else { cout << "impossible" << endl; }
	return 0;
}
0