c语言sscanf函数的用法是什么
369
2022-08-27
(Educational Codeforces Round 9)Thief in a Shop(dp)
Thief in a Shop
time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard output A thief made his way to a shop.
As usual he has his lucky knapsack with him. The knapsack can contain k objects. There are n kinds of products in the shop and an infinite number of products of each kind. The cost of one product of kind i is ai.
The thief is greedy, so he will take exactly k products (it’s possible for some kinds to take several products of that kind).
Find all the possible total costs of products the thief can nick into his knapsack.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 1000) — the number of kinds of products and the number of products the thief will take.
The second line contains n integers ai (1 ≤ ai ≤ 1000) — the costs of products for kinds from 1 to n.
Output
Print the only line with all the possible total costs of stolen products, separated by a space. The numbers should be printed in the ascending order.
Examples
input
3 2 1 2 3
output
2 3 4 5 6
input
5 5 1 1 1 1 1
output
5
input
3 3 3 5 11
output
9 11 13 15 17 19 21 25 27 33
题意 有n个数,然后这n个数里面选k个加起来 问你一共能加出来多少种
题解: 多项式加法,加k次,问你最后的数是哪些。 DP。dp[i]表示最少用多少个非a[1]能够构成a[1]*k+i的。
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~