結果
問題 |
No.247 線形計画問題もどき
|
ユーザー |
![]() |
提出日時 | 2017-05-25 19:09:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 684 bytes |
コンパイル時間 | 1,190 ms |
コンパイル使用メモリ | 157,668 KB |
実行使用メモリ | 48,512 KB |
最終ジャッジ日時 | 2024-09-19 19:15:20 |
合計ジャッジ時間 | 4,913 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 5 |
other | AC * 1 WA * 1 TLE * 1 -- * 20 |
ソースコード
#include"bits/stdc++.h" //#include<bits/stdc++.h> using namespace std; #define print(x) cout<<x<<endl; #define rep(i,a,b) for(int i=a;i<b;i++) #define REP(i,a) for(int i=0;i<a;i++) typedef long long ll; typedef pair<int, int> PI; typedef pair<int, PI> V; const ll mod = 100000000; int c, n, a[102]; int dp[102][100002] = {}; int dfs(int i, int j) { if (i == n)return mod; if (j == 0)return 0; if (dp[i][j] < mod)return dp[i][j]; for (int l = 0; j - l*a[i] >= 0; l++) { dp[i][j] = min(dp[i][j], l+dfs(i + 1, j - l*a[i])); } return dp[i][j]; } int main() { REP(i, 102)REP(j, 100002)dp[i][j] = mod; cin >> c; cin >> n; REP(i, n)cin >> a[i]; print(dfs(0, c)); return 0; }