ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Kovrov IT > задача:


2007.H. 50273 - Two Captains

Гость
• Обсуждение задачи (1)

Задачи сборника

• 2007.A. 50671 - Phalanx
• 2007.B. 50270 - Bitsorting
• 2007.C. 50640 - Cubes
• 2007.D. 50271 - Factorial
• 2007.E. 50663 - Lights
• 2007.F. 50690 - Parliament
• 2007.G. 50272 - Strange Numbers
• 2007.H. 50273 - Two Captains
• 2007.I. 50274 - Boundary Troops
• 2007.J. 50275 - Wedding
• 2007.K. 50276 - Nice Floor
• 2008.A. 50672 - Math and Soldiers
• 2008.B. 50261 - Roads
• 2008.C. 50262 - Brackets
• 2008.D. 50279 - Bit Decoder
• 2008.E. 50263 - Points

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Автор: Павел Кузнецов, ПГУ. Сложность Гамма

A boat which is certainly named "Beda" for some strange reasons happened to have two captains. That could probably be quite acceptable, but the two men don't get on very well as either of them thinks himself to be more important than the other. Once they have to draw up all the sailors in a row. Either of the two captains has his own view to the arrangement of the sailors. After a brief argument one of them says to the other: "Let me tell you which of the sailors should stand left of whom, and then you will place them as you like, taking into account my request". The second captain considered that a good idea as it gave them both an opportunity to equally participate in the arrangement of the rows. But he feared that the first captain could try to cheat and could put forward too strict requirements that will leave no sufficient freedom of choice. So, he is asking you now to make a program that will find the number of arrangements of the sailors in the rows using the list of the first captain's requirements.

Input
The first line of the input contains integers N and K (1 ≤ N ≤ 18, 0 ≤ K). N is the number of the sailors on board the ship (let all the sailors be numbered from 1 to N). K is the quantity of the first captain's requirements. Then there should be K lines each having two numbers X and Y. The requirement means that the sailor numbered X must be to the left of the sailor numbered Y in the row. It is provided that in each of the requirements 1 ≤ X, YN. And X is not equal to Y. No requirement is given twice.
Output
Write one number which is the answer to the question.

Input 1 Output 1
4 2
2 1
4 3
6
Comment on the sample: There are 4 sailors on the boat. Here are all the ways of arranging them:
2, 1, 4, 3
2, 4, 1, 3
2, 4, 3, 1
4, 2, 1, 3
4, 2, 3, 1
4, 3, 2, 1

Для отправки решений необходимо выполнить вход.

www.contester.ru