結果
| 問題 | 
                            No.247 線形計画問題もどき
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-06-09 05:22:35 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 30 ms / 2,000 ms | 
| コード長 | 325 bytes | 
| コンパイル時間 | 2,323 ms | 
| コンパイル使用メモリ | 194,784 KB | 
| 最終ジャッジ日時 | 2025-01-11 00:24:06 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 23 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int W,n; scanf("%d%d",&W,&n);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |                 int w; scanf("%d",&w);
      |                        ~~~~~^~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int main(){
	int W,n; scanf("%d%d",&W,&n);
	vector<int> dp(W+1,INF);
	dp[0]=0;
	rep(i,n){
		int w; scanf("%d",&w);
		rep(a,W-w+1) dp[a+w]=min(dp[a+w],dp[a]+1);
	}
	printf("%d\n",dp[W]<INF?dp[W]:-1);
	return 0;
}