文章
20
粉丝
412
获赞
12
访问
163.2k
#include <iostream>
using namespace std;
int main() {
int M, K, value[1005], dp[1005] = {0};
while(cin >> M) {
if(M == 0) break;
cin >> K;
for(int i = 0;i < K;i++)
cin >> value[i];
for(int i = 1;i <= M;i++) {
dp[i] = 999999;
for(int j = 0;j < K;j++) {
if(i >= value[j]) {
dp[i] = min(dp[i-value[j]]+1, dp[i]);
}
}
}
if(dp[M] == 999999) cout << "Impossible" << endl;
else cout << dp[M] << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发