TopCoder problem "CorruptMages" used in TCHS SRM 59 (Division I Level One)



Problem Statement

    Once there was a powerful artifact and the legend said that the owner of this artifact will have unlimited power. A long time ago a few mages found this artifact and decided that nobody should own it. So each of them cast a protection spell on it. You learned about that and decided that the artifact should be yours, so the plan is to give bribes to the mages to make them remove their spells. You know that if you give a bribe to the i-th mage, he will easily remove his own spell and up to power[i] spells of any other mages. Now you want to calculate the minimal number of mages you should pay to remove all spells from the artifact.
 

Definition

    
Class:CorruptMages
Method:minimalNumber
Parameters:int[]
Returns:int
Method signature:int minimalNumber(int[] power)
(be sure your method is public)
    
 

Constraints

-power will contain between 1 and 50 elements, inclusive.
-Each element of power will be between 0 and 50, inclusive.
 

Examples

0)
    
{0,0,0,0,0}
Returns: 5
Here each of five mages can only remove his own spell. So, we have to give bribes to all of them.
1)
    
{0,1,3,0}
Returns: 1
Now there is a powerful mage who can remove his own spell and all three spells of his colleagues. So it is enough to give a bribe to him.
2)
    
{0}
Returns: 1
We have to give a bribe to the single mage.
3)
    
{0,1,2,2,0,1,3,1}
Returns: 3

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10111

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13528&pm=10111

Writer:

Alexus

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Greedy