結果

問題 No.247 線形計画問題もどき
ユーザー hogeover30hogeover30
提出日時 2016-04-13 03:30:32
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 399 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 51,748 KB
最終ジャッジ日時 2024-04-27 02:19:41
合計ジャッジ時間 698 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:5: error: ‘vector’ was not declared in this scope
    9 |     vector<int> a(n);
      |     ^~~~~~
main.cpp:4:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    3 | #include <cstdio>
  +++ |+#include <vector>
    4 | using namespace std;
main.cpp:9:12: error: expected primary-expression before ‘int’
    9 |     vector<int> a(n);
      |            ^~~
main.cpp:10:17: error: ‘a’ was not declared in this scope
   10 |     for(int& e: a) cin>>e;
      |                 ^
main.cpp:12:12: error: expected primary-expression before ‘unsigned’
   12 |     vector<unsigned> dp(c+1, -1);
      |            ^~~~~~~~
main.cpp:13:5: error: ‘dp’ was not declared in this scope
   13 |     dp[c]=0;
      |     ^~
main.cpp:16:20: error: ‘a’ was not declared in this scope
   16 |             if (i>=a[j] and ~dp[i])
      |                    ^

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int c, n; cin>>c>>n;
    vector<int> a(n);
    for(int& e: a) cin>>e;
    
    vector<unsigned> dp(c+1, -1);
    dp[c]=0;
    for(int i=c; i>=0; --i)
        for(int j=0; j<n; ++j)
            if (i>=a[j] and ~dp[i])
                dp[i-a[j]]=min(dp[i-a[j]], dp[i]+1);

    cout<<(int)dp[0]<<endl;
}
0