#include <iostream> #include<cstring> using namespace std; //本题就是一个01背包问题 const int N = 25; const int inf = 0x3f3f3f3f; int v[N]; int f[110];//容量最大是100 int main() { int m; while (cin >> m) { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> v[i]; memset(f, 0x3f, sizeof f); f[0] = 0; for (int i = 1; i <= n; i++) for (int j = m; j >= v[i]; j--) { f[j] = min(f[j], f[j - v[i]]+1);//这个的属性是选了几张邮票 } if (f[m] == inf)cout << 0; else cout << f[m] << endl; } } // 64 位输出请用 printf("%lld")