/* -*- coding: utf-8 -*- * * 733.cc: No.733 分身並列コーディング - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 17; const int NBITS = 1 << MAX_N; const int INF = 0x7f7f7f7f; /* typedef */ /* global variables */ int ts[MAX_N]; int dp[NBITS][MAX_N + 1]; /* subroutines */ inline void setmin(int &a, int b) { if (a > b) a = b; } /* main */ int main() { int t, n; scanf("%d%d", &t, &n); for (int i = 0; i < n; i++) scanf("%d", &ts[i]); int nbits = 1 << n; memset(dp, 0x7f, sizeof(dp)); memset(dp[0], 0, sizeof(dp[0])); for (int bits = 0; bits < nbits; bits++) for (int i = 0; i <= n; i++) if (dp[bits][i] < INF) { if (i < n && dp[bits][i] <= t) dp[bits][i + 1] = 0; for (int j = 0, bj = 1; j < n; j++, bj <<= 1) if (! (bits & bj)) setmin(dp[bits | bj][i], dp[bits][i] + ts[j]); } int mini = 0; for (; mini <= n; mini++) if (dp[nbits - 1][mini] == 0) break; printf("%d\n", mini); return 0; }