Handing out candies
InterviewTime limit2sMemory limit512 MB
For every K, count the ways to choose one candy of each brand 1 through K, and print the total over all K.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
You want to hand out candies to the participants of an algorithm camp.
You have candies, and every candy has a brand written as an integer.
First you decide , the number of candies you hand out. Then you pick exactly one candy of each brand from brand through brand .
can be any value from to , and two candies of the same brand count as different candies. Write a program that computes the total number of ways to pick the candies, summed over every .
Input
The first line contains the number of candies . ()
The second line contains the brands of the candies, separated by spaces. Each brand is an integer between and .
Output
Print the number of ways to pick the candies on the first line. The value is smaller than .