惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
博客园 - Franky
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
爱范儿
爱范儿
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
Microsoft Security Blog
Microsoft Security Blog
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔
Permutation
2022-11-14 · via 某岛

November 14, 2022

由于上一场 G 题没做出来。。打算重新复习一下各种排列相关的知识。。。

Table of Contents

  • Combinatorial Problems and Exercises, 2nd Edition, László Lovász, #3 Permutations
  • The Art of Computer Programming, Vol. 3 Sorting and Searching, 2nd Edition, Donald E. Knuth, 5.1. Combinatorial Properties of Permutations

第一部分

错位排列()

自反排列

交错排列

类 Catalan 递推公式

类 Pascal 递推公式

生成函数

第二部分

循环分解

不动点

逆序对

#include <lastweapon/io>
#include <lastweapon/number>
using namespace lastweapon;

const int N = int(1e3) + 9;

int a[N], mx[N], mn[N], cc[N];
int n;

VI circle() {
    bool static used[N]; RST(used);
    VI z;
    REP(i, n) if (!used[i]) {
        int x = i; used[x] = true; int c = 1;
        while (!used[a[x]-1]) {
            x = a[x]-1;
            used[x] = true;
            ++c;
        }
        z.PB(c);
    }
    return z;
}


bool used[N];

void dfs(int k = 0) {

    if (k == n) {
        //REP(i, n) cout << a[i] << " "; cout << endl;
        VI r = circle();
        ++mx[*max_element(ALL(r))];
        ++mn[*min_element(ALL(r))];
        ++cc[SZ(r)];
    } else {
        REP_1(i, n) if (!used[i]) {
            used[a[k] = i] = true;
            dfs(k+1);
            used[i] = false;
        }
    }
}


int main(){

#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif

	//scanf("%d%d",&n,&MOD);
	REP_1(i, 10) {
        //RD(n);

        RST(used); RST(mn); RST(mx); RST(cc);
        n = i; dfs();
        //REP_1(i, n) cout << mx[i] <<" "; cout << endl;
        //REP_1(i, n) cout << mn[i] <<" "; cout << endl;
        REP_1(i, n) cout << cc[i] <<" "; cout << endl;
	}
}

Posted by xiaodao
Category: 日常