結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2015-08-06 14:04:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 449 bytes |
コンパイル時間 | 1,729 ms |
コンパイル使用メモリ | 158,396 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 11:09:22 |
合計ジャッジ時間 | 2,313 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%d%d",&C,&N); | ~~~~~^~~~~~~~~~~~~~ main.cpp:9:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | for(int i=0;i<N;i++)scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>using namespace std;const int INF=1e9;int C,N,a[100000];int dp[100005];int main(){scanf("%d%d",&C,&N);for(int i=0;i<N;i++)scanf("%d",&a[i]);fill_n(dp,100005,INF);dp[0]=0;for(int i=0;i<N;i++){for(int j=1;j<=C;j++){if(j-a[i]<0)continue;dp[j]=min(dp[j],dp[j-a[i]]+1);}}if(dp[C]==INF)puts("-1");else printf("%d\n",dp[C]);return 0;}