結果
問題 | No.247 線形計画問題もどき |
ユーザー |
![]() |
提出日時 | 2015-07-17 23:38:51 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,142 bytes |
コンパイル時間 | 806 ms |
コンパイル使用メモリ | 78,000 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-08 09:39:26 |
合計ジャッジ時間 | 1,387 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 WA * 3 |
ソースコード
#include <iostream> #include <algorithm> #include <functional> #include <string> #include <climits> #include <vector> #include <numeric> #include <complex> #include <map> #include <bitset> using namespace std; //#define __int64 long long #define long __int64 #define REP(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) REP(i,0,n) const int Vecy[4] = {0,-1,0,1}; const int Vecx[4] = {1,0,-1,0}; int x[100] = {0}; int total,n; int a[100] = {0}; bool func(int op, int left, int &ans){ if(left == 0){ ans = min(ans, accumulate(x, x+n, 0)); return true; } if(op >= n){ return false; } x[op] = left / a[op]; if(ans == INT_MAX){ for(int i=0; i<5; i++){ func(op+1, left - a[op] * x[op], ans); if(x[op] == 0){ break; } x[op] --; } return false; }else{ for(int i=0; i<3; i++){ func(op+1, left - a[op] * x[op], ans); if(x[op] == 0){ break; } x[op] --; } return false; } } int main(){ int ans = INT_MAX; cin >> total >> n; rep(i,n){ cin >> a[i]; } sort(a, a + n, greater<int>()); //降順 func(0, total, ans); cout << (ans == INT_MAX ? -1 : ans) << endl; return 0; }