Блог пользователя v0rtex

Автор v0rtex, история, 4 года назад, По-английски

An array of size N is given and a value K. You have to find the minimum subset size so that subset sum is exactly equal to K, if not print -1. 0 < K, a[i], N < 10^6.

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Isn't this the famous coin change problem? You can easily find the solution online.

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I encountered a similar problem recently, can someone suggest some solution:
Given an array A of size N, find the number of subsets of size exactly K that add up to S.
e.g:

A = [1,1,1,2,3,4]
K=3, S=6
answer: 6

explanation (0 based indexing)

[0,1,5]
[0,2,5]
[1,2,5]
[0,3,4]
[1,3,4]
[2,3,4]

I don't remember the constraints, but let's say 1 <= N,S <= 1000

and would it really be possible to solve under normal time-limits i.e. 1 or 2 sec if N,S were 10^5?