zoukankan      html  css  js  c++  java
  • bzoj1430 小猴打架 prufer 序列

    题目传送门

    https://lydsy.com/JudgeOnline/problem.php?id=1430

    题解

    prufer 序列模板题。

    一个由 (n) 个点构成的有标号无根树的个数为 (n^{n-2})

    证明就是 prufer 序列,可以看我的学习笔记。

    https://www.cnblogs.com/hankeke/p/prufer.html

    然后因为一棵树的加边顺序随意,所以还需要乘上 ((n-1)!)

    所以最后答案为 (n^{n-2}(n-1)!)


    #include<bits/stdc++.h>
    
    #define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
    #define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
    #define fi first
    #define se second
    #define pb push_back
    
    template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
    template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b , 1 : 0;}
    
    typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;
    
    template<typename I> inline void read(I &x) {
    	int f = 0, c;
    	while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
    	x = c & 15;
    	while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
    	f ? x = -x : 0;
    }
    
    const int P = 9999991;
    
    int n;
    
    inline void work() {
    	int ans = 1;
    	for (int i = 1; i <= n - 2; ++i) ans = (ll)ans * n % P;
    	for (int i = 1; i <= n - 1; ++i) ans = (ll)ans * i % P;
    	printf("%d
    ", ans);
    }
    
    inline void init() {
    	read(n);
    }
    
    int main() {
    #ifdef hzhkk
    	freopen("hkk.in", "r", stdin);
    #endif
    	init();
    	work();
    	fclose(stdin), fclose(stdout);
    	return 0;
    }
    
  • 相关阅读:
    无旋转Treap简介
    bzoj 4318 OSU!
    bzoj 1419 Red is good
    bzoj 4008 亚瑟王
    bzoj 1014 火星人prefix
    更多的莫队
    bzoj 3489 A simple rmq problem
    洛谷 2056 采花
    NOIP 2017 游(划水)记
    UVa 11997 K Smallest Sums
  • 原文地址:https://www.cnblogs.com/hankeke/p/bzoj1430.html
Copyright © 2011-2022 走看看