Plus
Pin


Problem description Progress
ID 38499. Skittles coloring
Темы: Cycles    Combinatorics   

N pins are placed in a row. Gromozeka paints each of them one of the K colors from her paint cans. For aesthetic reasons, any two adjacent pins should be painted in different colors. Find the number of possible ways to color the skittles.

Input
The input string contains two integers N and K (\(1<=N<=1000\),  \(2<=K<=1000\)).

Imprint
Display the answer to the problem. It is guaranteed that the correct answer does not exceed \(2^{31}-1\).
 

 

Examples
# Input Output
1 2 2 2
1 1 10 10

 

ID 38588. March
Темы: Combinatorics   

There is a N person. The name of the ith person is Si . We want to select three people so that the following conditions are met:
- The name of each selected person starts with M, A, R, C or H< /code>; 
- there are no people whose names start with the same letter among the selected people.
How many ways are there to choose three people without paying attention to the order?

Input
The first line contains an integer (\(1<=N<=10^5\)) The next N lines contain names S - a string consisting only of English capital letters, the string length is not more than 10 characters. All names are different.

Imprint
Print the answer to the problem. Please note that the answer may not be a 32-bit integer type.
 

 

Examples
# Input Output Explanation
1 5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI
2 Three people can be selected in the following ways:

- MASHIKE, RUMOI, HABORO
MASHIKE, RUMOI, HOROKANAI

Answer: 2

2 4
ZZ
ZZZ
Z
ZZZZZZZZZZ
0  
3 5
CHOKUDAI
RNG
MAKOTO
AOKI
RINGO
7  

ID 38634. Number cookies - 2
Темы: Combinatorics    Dynamic programming   

Gromozeka has N cookies. The i-th (1<=i<=N) cookie has an integer xi written on it. He chooses one or more of these cookies so that the average value of the integers written on the chosen cookies is A.
In what ways can he make his choice?

Input
The first line contains two integers N (1<=N<=50) and A (1<=A<=50). The second line contains N integers - xi (1<=xi<=50).

Imprint
Print one number - the number of ways to choose such cookies so that the average value of all written numbers on the cookies is exactly A.
 

 

Examples
# Input Output Note
1 4 8
7 9 8 9
5 Below are 5 ways to choose cookies so that the average is 8.
1) Choose the 3rd cookie.
2) Choose the 1st and 2nd cookies.
3) Choose the 1st and 4th cookies.
4) Choose the 1st, 2nd and 3rd cookies.
5) Choose the 1st, 3rd and 4th cookies.
2 3 8
6 6 9
0  
3 8 5
3 6 2 8 7 6 5 9
19  
4 33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
8589934591 The response may not be a 32-bit integer.

 

ID 38656. Cards for three
Темы: Combinatorics   

Silent, Grumpy and Pilyulkin play a card game for three. The rules of the game are as follows.
First, each of the three players has a deck of cards.
There are N cards in Pilyulkin's deck, M cards in Silent Man's deck, and K cards in Grumbler's deck. Each card has a letter p, m or v written on it. The order of cards in decks cannot be changed. The players take turns. Pilyulkin goes first.
If there is at least one card in the current player's deck, discard the top card in the deck.
Then the next turn goes to the player whose name begins with the letter on the discarded card. For example, if the card says "p", the next turn goes to Pilyulkin.
If the current player's deck is empty, the game ends and the current player wins the game.
There are 3N + M + K possible layouts for three players' starting decks.
How many of these patterns will lead Pilyulkin to victory? Since the answer can be large, print it modulo 1000000007 (= 109 +7).

Input
The input is three integers N, M and K (2<=N, M, K <=3*105).

Imprint
Print the number of patterns winning for Pilyulkin modulo 1000000007 (= 109 +7).

 

Examples
# Input Output Explanation
1 1 1 1 17 If Pilyulkin's card is p, then Pilyulkin will win regardless of the Silent and Grumpy cards. There are 3 × 3 = 9.
If Pilyulkin's card is m, Pilyulkin will only win when Silent's card is p, or when Silent's card is v and Grumble's card is p. There are 3 + 1 = 4 such templates in total.
If Pilyulkin's card is v, Pilyulkin will only win when Grumpy's card is p, or when Grumpy's card is m and Grumpy's card is p. There are 3 + 1 = 4 such templates in total.
Thus, there are 9 + 4 + 4 = 17 patterns in total that will lead to Pilyulkin's victory.
2 4 2 2 1227  
3 1000 1000 1000 261790852  

 

ID 38928. Until the New Year - 1
Темы: Cycles    Combinatorics   

Snezhik Sugrobovich put a row of N Christmas balls in order to color them. He decided that each ball would be one of K colors. At the same time, Snezhik Sugrobovich wants any two adjacent Christmas tree balls & nbsp; were painted in different colors. Find the number of possible ways to color the Christmas balls.

Input
The input string contains two integers N and K (\(1<=N<=1000\),  \(2<=K<=1000\)).

Imprint
Display the answer to the problem. It is guaranteed that the correct answer does not exceed \(2^{31}-1\).

 

Examples
# Input Output
1 2 2 2
1 1 10 10