結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2017-12-23 08:11:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 342 ms / 5,000 ms |
コード長 | 699 bytes |
コンパイル時間 | 790 ms |
コンパイル使用メモリ | 64,208 KB |
実行使用メモリ | 66,560 KB |
最終ジャッジ日時 | 2024-12-27 17:53:38 |
合計ジャッジ時間 | 5,313 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#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; }