文章
17
粉丝
177
获赞
2
访问
119.4k
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
using namespace std;
int main(){
int values[20];
vector<int> dp(100, INT_MAX);
int M, N;
while(cin >> M >> N){
dp[0] = 0;
for (int i = 0; i < N;i++)
cin >> values[i];
for (int i = 0; i < N;i++){
for (int j = M; j >= values[i];j--)
{
if(dp[j - values[i]] != INT_MAX)
dp[j] = min(dp[j], dp[j - values[i]] + 1);
}
}
if(dp[M] != INT_MAX)
cout << dp[M] << endl;
else
cout << 0 << endl;
for (int i = 0; i < 100;i++)
dp[i] = INT_MAX;
}
}
登录后发布评论
暂无评论,来抢沙发