結果
| 問題 |
No.50 おもちゃ箱
|
| コンテスト | |
| ユーザー |
Ysmr_Ry
|
| 提出日時 | 2014-11-16 20:19:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 5,000 ms |
| コード長 | 818 bytes |
| コンパイル時間 | 361 ms |
| コンパイル使用メモリ | 39,552 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 20:45:26 |
| 合計ジャッジ時間 | 1,598 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf( "%d", &N );
| ~~~~~^~~~~~~~~~~~
main.cpp:16:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf( "%d", A+i );
| ~~~~~^~~~~~~~~~~~~
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf( "%d", &M );
| ~~~~~^~~~~~~~~~~~
main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf( "%d", B+i );
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include<limits>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)
#define repd(i,a) for(int i=(a);i>=0;--i)
const int MAX_N = 10, MAX_M = 10, INF = std::numeric_limits<int>::max()>>2;
int N, M;
int A[MAX_N], B[MAX_M];
int main()
{
scanf( "%d", &N );
rep( i, N )
scanf( "%d", A+i );
scanf( "%d", &M );
rep( i, M )
scanf( "%d", B+i );
std::vector<int> cost( 1<<N );
rep( i, 1<<N ) rep( k, N ) if( i>>k&1 )
cost[i] += A[k];
std::vector<int> dp( 1<<N, INF );
dp[0] = 0;
rep( i, M ) repd( j, (1<<N)-1 )
{
if( dp[j] == INF )
continue;
repd( k, (1<<N)-1 )
{
if( j&k || cost[k] > B[i] )
continue;
dp[j|k] = std::min( dp[j|k], dp[j]+1 );
}
}
printf( "%d\n", dp[(1<<N)-1]==INF?-1:dp[(1<<N)-1] );
return 0;
}
Ysmr_Ry