結果
| 問題 |
No.50 おもちゃ箱
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-03-17 13:49:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,152 bytes |
| コンパイル時間 | 351 ms |
| コンパイル使用メモリ | 55,580 KB |
| 最終ジャッジ日時 | 2024-11-14 19:35:50 |
| 合計ジャッジ時間 | 801 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:16: error: ‘pow’ was not declared in this scope
25 | rep (j,pow(2,n)) {
| ^~~
main.cpp:8:36: note: in definition of macro ‘REP’
8 | #define REP(i,s,e) for (i = s; i < e; i++)
| ^
main.cpp:25:9: note: in expansion of macro ‘rep’
25 | rep (j,pow(2,n)) {
| ^~~
main.cpp:42:24: error: ‘pow’ was not declared in this scope
42 | if (dp[i][(int)pow(2,n)-1]) {
| ^~~
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8
typedef long long ll;
int main() {
int i, j, k, l, n, m;
bool dp[11][1024] {};
int a[10], b[10];
cin >> n;
rep (i,n) cin >> a[i];
cin >> m;
rep (i,m) cin >> b[i];
sort(b,b+m,greater<int>{});
dp[0][0] = true;
REP (i,1,11) {
rep (j,pow(2,n)) {
if (dp[i-1][j]) {
rep (k,pow(2,n)) {
if ((~j & k) == k) {
int sum = 0;
rep (l,n) {
if (k & (1<<l))
sum += a[l];
}
if (b[i-1] >= sum)
dp[i][j|k] = true;
}
}
}
}
}
rep (i,11) {
if (dp[i][(int)pow(2,n)-1]) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
h_noson