当前位置:网站首页>Staggered and permutation combination formula
Staggered and permutation combination formula
2022-06-28 03:56:00 【I am already furious!】
Dislocation
> Concept
First introduce a concept , What is wrong arrangement ;
Staggering is talking about an array with order , Each of these numbers , It is not in its original position after arrangement .
for example 1 2 3 4 5
among 1 You can't put it in the first place ,2 You can't put it in the second place , And so on .
Here is a diagram for you to understand the following formula
If you want to understand better, here is a link
Heigu Xiaojian Mogok yyds
The formula
int dp[25];
dp[1]=0;
dp[2]=1;
for(i=3;i<=n;i++)// Since the first two need to be pre stored, start from three
dp[i]=(i-1)*(dp[i-1]+dp[i-2]);
For staggered arrangement, we can use the formula
Combined calculation


So we can calculate n,m,n-m To find the factorial of
int mo=1,zi=1,z2=1,z3=1;
for(i=1;i<=n;i++)// This is a n The factorial
mo*=i;
for(i=1;i<=(n-m);i++)//n-m The factorial
z2*=i;
for(i=1;i<=m;i++)//m The factorial
z3*=i;
This is a wrong question ( Statistics of students' grades )
The main idea of the topic , Given a number of students , Yes n Famous student ,1≤n≤15, Mr. Ke said that the ranking statistics of all students were wrong
We can assume that the correct order is 1 2 3 ……, Or in any order .
The code is as follows
#include<bits/stdc++.h>
using namespace std;
#define MAX 0x3f3f3f3f
typedef long long ll;
#define bug(a) cout<<endl<<"*"<<a<<endl;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
ll dis[30];
dis[1]=0;
dis[2]=1;
for(int i=3;i<=n;i++){
dis[i]=(i-1)*(dis[i-2]+dis[i-1]);
}
cout<<dis[n]<<endl;
}
Input
3
Output
2
n=3 when , There are two situations :
3 1 2
2 3 1
Finally, let's say , Mogok yyds.
边栏推荐
猜你喜欢

从遇见大咖到成为大咖,昇腾AI开发者创享日给开发者带来无限可能

leetcode:494. All methods of adding and subtracting operators to the array to get the specified value

Summary of the use of composition API in the project

以自动化赋能转型,飞鹤乳业加速迈向数字化!

A preliminary study of blackbody radiation

Chapter IX app project test (3) test tools

Adder - Notes

局域网内共享打印机的几种方式

How does the open-ended Hall current sensor help the transformation of DC power distribution?

使用信号分析器
随机推荐
数字电路学习笔记(二)
数字电路学习笔记(一)
Detailed explanation of KVM common commands
光的粒子说(光电效应/康普顿效应)
继承
Arrangement of basic electrical knowledge (I)
黑体辐射初探
leetcode:494.数组中添加加减运算符得到指定值的所有方法
Circular sliding auto adsorption UI tool that monkeys can use
数字有为,易步到位 华为携“5极”明星产品加速布局商业市场
第14章 AC-DC电源前级电路 笔记一
Huawei equipment WLAN basic service configuration command
Summary of the use of composition API in the project
ERP升级的另一种选择,MES系统
Go speed
A pit filling trip based on LNMP to build a personal website
电子地图坐标系统研究整理
[graduation season] graduate summary
可扩展数据库(上)
STM32外设SDIO和SD卡的配置