結果

問題 No.45 回転寿司
ユーザー newlife171128newlife171128
提出日時 2017-12-23 08:11:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 362 ms / 5,000 ms
コード長 699 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 65,000 KB
実行使用メモリ 66,620 KB
最終ジャッジ日時 2023-08-27 15:57:17
合計ジャッジ時間 5,061 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
15,304 KB
testcase_01 AC 119 ms
26,700 KB
testcase_02 AC 256 ms
47,124 KB
testcase_03 AC 279 ms
53,572 KB
testcase_04 AC 133 ms
28,756 KB
testcase_05 AC 6 ms
4,520 KB
testcase_06 AC 92 ms
21,580 KB
testcase_07 AC 226 ms
44,764 KB
testcase_08 AC 27 ms
9,096 KB
testcase_09 AC 269 ms
52,040 KB
testcase_10 AC 63 ms
16,020 KB
testcase_11 AC 20 ms
7,492 KB
testcase_12 AC 241 ms
48,264 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 75 ms
18,512 KB
testcase_16 AC 34 ms
10,408 KB
testcase_17 AC 60 ms
15,140 KB
testcase_18 AC 36 ms
10,776 KB
testcase_19 AC 184 ms
38,216 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 5 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 78 ms
18,800 KB
testcase_27 AC 176 ms
36,856 KB
testcase_28 AC 87 ms
20,712 KB
testcase_29 AC 173 ms
34,292 KB
testcase_30 AC 163 ms
33,812 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 362 ms
66,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>

using namespace std;
int n = 0;
int nums[1001];
int b[1001][31000];
int ans = 0;
void dfs(int i, int sum, bool judge) {
	if (i == n) {
		ans = max(ans, sum);
		/*cout << i << " " << ans << endl;*/
		return;
	}
	if(b[i][sum] !=0){
		return;
	}

	dfs(i + 1, sum, false);
	b[i+1][sum] =1;

	if (!judge) {
		dfs(i + 1, sum + nums[i], true);
	/*	b[i+1][sum+nums[i]] =1;*/
	}/* else {
		dfs(i + 1, sum, false);
	}*/

	return;
}

int main() {

	cin >> n;

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

	dfs(0, 0, false);

	cout << ans << endl;

	return 0;
}
0