You are not logged in. Please login at www.codechef.com to post your questions!

×

finding subsets in an array

Pls suggest an algorithm to find the maximum no. of subset of length k in an array of length m where k<=m , having sum equal to a constant factor...

e.g an array of length 11

2 5 1 2 4 1 6 5 2 2 1

k=6, constant factor = sum of largest k values in the array= 6 + 5 + 5 + 4 + 2 + 2 = 24 ??

asked 13 Mar '14, 11:47

zargus's gravatar image

2★zargus
17662136
accept rate: 0%


copy the values into a new array name sbs length k. then find max either with what ever build in function or write it down your self.

hint for max func()

for i =0 i<k-1 i++ {

if sbs[i]<sbs[i+1] max= sbs[i+1]

else if sbs[i]>sbs[i+1] max =sbs[i]

else if sbs[i] = sbs[i+1] Continue

}

sbs: short of subset

link

answered 13 Mar '14, 13:50

eng_ghanima's gravatar image

0★eng_ghanima
70124
accept rate: 11%

edited 16 Mar '14, 11:48

i need to find the max no. of subset of length k not max k !!

(13 Mar '14, 15:28) zargus2★

@zarqus I edited above answer to make sense, look at it now. Advice: extract the code on sperate lines, it will be more clear.

(16 Mar '14, 11:38) eng_ghanima0★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,658
×1,478

question asked: 13 Mar '14, 11:47

question was seen: 4,760 times

last updated: 16 Mar '14, 11:48