結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-01-04 09:41:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 607 bytes |
コンパイル時間 | 685 ms |
コンパイル使用メモリ | 60,660 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-19 11:08:10 |
合計ジャッジ時間 | 2,574 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 RE * 9 |
ソースコード
#include <iostream> #include <vector> using namespace std; int n; vector<int> w; bool memo[100][10000] = {0}; bool solve(int i, int wi, int wj) { if(memo[i][wi]) return false; memo[i][wi] = true; if(i >= n) return wi == wj; if(solve(i + 1, wi + w[i], wj)) return true; if(solve(i + 1, wi, wj + w[i])) return true; return false; } int main(void) { cin >> n; w.resize(n); for(int i = 0; i < n; i++) cin >> w[i]; if(solve(0, 0, 0)) cout << "possible" << endl; else cout << "impossible" << endl; return 0; }