UPC- monkey fight

Learning is like rowing upstream

Monkey fight

Title Description

Start forest there are N only know each other little monkeys, they often fight, but the fight must not be both a good friend. After each frame is finished, the two sides fight, and their friends will know each other and become good friends. After N-1 times fight, the whole forest monkey will become good friends.
The question now is, a total of how many different fights process.
For example, when N = 3, there {} {1-2, 1-3 1-2, 2-3 1-3, 2-3} {} {} {1-3,1-2 2-3, 2-3,1-3} {1-2} six different fighting process.

Entry

An integer N.

Export

Line, program number mod 9999991.

Sample Input

4

Sample Output

96

Hint

50% of the data N <= 10 . 3 .
100% data N <= 10 . 6 .

Topic ideas
This question requires a knowledge point is the number of columns Purfer
image of chestnuts is to a point with the rest of the n-1 sets connected to the root by which method.
A total of n- n-2- cases.
Since then determine the root of this, then the rest of the n-1 have (n-1)! The method of permutations
it, the answer is (n--. 1)! * N- n--2
through the normal analog operation can be made out
ACcode show as below

#include<algorithm>
#include<iostream>
#include<string.h>
#include<utility>
#include<stdio.h>
#include<vector>
#include <stack>
#include<string>
#include<math.h>
#include<cmath>
#include<queue>
#include<map>
#pragma warning(disable:4244)
#define PI 3.1415926536
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll ll_inf = 9223372036854775807;
const int int_inf = 2147483647;
const short short_inf = 32767;
const char char_inf = 127;
inline ll read() {
	ll c = getchar(), Nig = 1, x = 0;
	while (!isdigit(c) && c != '-')c = getchar();
	if (c == '-')Nig = -1, c = getchar();
	while (isdigit(c))x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar();
	return Nig * x;
}
inline void out(ll a)
{
	if (a < 0)putchar('-'), a = -a;
	if (a >= 10)out(a / 10);
	putchar(a % 10 + '0');
}
ll qpow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1)res = (res * x) % mod;
		x = (x * x) % mod; n >>= 1;
	}
	return res;
}
#define read read()
ll ans = 0;
int main()
{
	ll n = read;
	ans = qpow(n, n - 2, 9999991);
	for (int i = 1; i < n; i++)
	{
		ans *= i;
		ans %= 9999991;
	}
	cout << ans << endl;
	return 0;
}
There is a road ground for the tracks, Boundless Learning bitter for the boat.
Published 32 original articles · won praise 11 · views 1184

Guess you like

Origin blog.csdn.net/qq_35339563/article/details/104783279