题目:https://www.acwing.com/problem/content/232/ #include<bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; ; ll dp[maxn],inv[maxn],fac[maxn],inv_fac[maxn]; void init() { inv[]=inv[]=inv_fac[]=fac[]=; dp[]=;dp[]=; ; i<…
[BZOJ4517][Sdoi2016]排列计数 Description 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰好有 m 个数是稳定的 满足条件的序列可能很多,序列数对 10^9+7 取模. Input 第一行一个数 T,表示有 T 组数据. 接下来 T 行,每行两个整数 n.m. T=500000,n≤1000000,m≤1000000 Output 输出 T 行,每行一个…
L - 计数,排列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!  做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样.  话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,…
排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9583    Accepted Submission(s): 3485 Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数.   Input 每组数据占一行,代表四张卡片上…
N wizards are attending a meeting. Everyone has his own magic wand. N magic wands was put in a line, numbered from 1 to n(Wand_i owned by wizard_i). After the meeting, n wizards will take a wand one by one in the order of 1 to n. A boring wizard deci…
思路: 预处理错排 然后C(n,m)*s[n-m-1]就是答案了 特判n-m-1<0 //By SiriusRen #include <cstdio> using namespace std; #define int long long ,N=; int cases,n,m,fac[N],s[N]; int pow(int x,int y){ ; while(y){ )res=res*x%mod; x=x*x%mod,y>>=; }return res; } )%mod*po…
点此看题面 大致题意:已知 \(p\)为\(n\)的一个排列,定义\(A(p)_i=min_{j=1}^ip_j\),若用\(q_i\)表示\(p\)第\(i\)小的前缀的长度(以值为第一关键字,下标为第二关键字),先给你\(q\),请你求出字典序最小的\(p\). 简单分析·基本结论 让我们来仔细研究一下样例: \(i\) \(1\) \(2\) \(3\) \(4\) \(5\) \(p_i\) \(3\) \(4\) \(2\) \(5\) \(1\) \(A(p)_i\) \(3\) \…
Dressing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2964 Accepted Submission(s): 1291 Problem Description Wangpeng has N clothes, M pants and K shoes so theoretically he can have N×M×K differ…
1707: 丧心病狂的计数 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 237  Solved: 105 SubmitStatusWeb Board Description 有一天,stubird发现了n个糖罐,里面有很多糖罐,很喜欢吃糖的Stubrid当然想吃最多的糖, 但是他只能带走k个罐子,问他最多能带走多少颗糖? Input 第一行T,表示有T(T<=50)个测试样例 第二行n,k,表示有n个罐子,最多只能带走k个罐子(k<=n<…
画个图就很容易推出公式: 设mn=min(m,n),mx=max(m,n) 对角线上: 横向:m*C(n,2) 纵向:n*C(m,2) 因为所有的C函数都是只拿了两个,所以可以优化下.不过不优化也过了= = #include <iostream> using namespace std; #define LL long long int n,m; LL P(long n,long m) { ; ) { p*=n; n--; m--; } return p; } LL C(long n,long…