文章
68
粉丝
691
获赞
26
访问
578.4k
https://blog.csdn.net/csyifanZhang/article/details/106128211
↑详细题解
#define ll int
#define inf 0x3f3f3f3f
#define MAX 55
#define vec vector<ll>
#define P pair<ll,ll>
//dp[j]:凑出j需要的最小邮票数目
int K, N, a[MAX], dp[2000005];
int main() {
while (cin >> K >> N) {
memset(dp, 0, sizeof(dp));
ll maxx = 0;
for (int i = 1; i <= N; i++)cin >> a[i];
sort(a + 1, a + N + 1);//一定要排序
int i = 0;
while (dp[i] <= K) {
i++; dp[i] = inf;
for (int j = 1; j <= N && a[j] <= i; j++)
dp[i] = min(dp[i], dp[i - a[j]] + 1);
}
cout << i - 1 << endl;
}
}
登录后发布评论
暂无评论,来抢沙发