//TLE解法 #include #include #define rep(i, n) for(i = 0; i < n; i++) using namespace std; int T, n; int t[17]; int dp[1 << 17]; int dfs(int rem) { int i, j; if (rem == 0) return 0; if (dp[rem] != -1) return dp[rem]; int id[17], cnt = 0; rep(i, n) { if ((rem >> i) & 1) { id[cnt++] = i; } } int ret = n; rep(i, (1 << cnt)) { int sumT = 0, sol = 0; rep(j, cnt) { if ((i >> j) & 1) { sumT += t[id[j]]; sol += (1 << id[j]); } } if (sumT <= T && sol != 0) { int res = dfs(rem - sol) + 1; ret = min(ret, res); } } return dp[rem] = ret; } int main() { int i; cin >> T >> n; rep(i, n) cin >> t[i]; rep(i, (1 << n)) dp[i] = -1; int res = dfs((1 << n) - 1); cout << res << endl; return 0; }