当前位置:网站首页>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.
边栏推荐
猜你喜欢

【毕业季】研究生の毕业总结

使用信号分析器

一文告诉你什么是 Kubernetes

Execution plan in MySQL of database Series

Door level modeling - learning notes

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

Chapter IX app project test (3) test tools

谈云原生,不得不谈的容器

Detailed explanation of iptables firewall rules and firewalld firewall rules

A solution to the inefficiency of setting debug mode in developing flask framework with pychar
随机推荐
Online DDL implementation mechanism in InnoDB of database Series
Anaconda command usage
黑體輻射初探
图片的懒加载和预加载
Web APIs DOM-事件基础丨黑马程序员
工业物联网将取代人工发展吗?
Extensible database (Part 2)
月赛补题
第一章 Bash 入门
Circular sliding auto adsorption UI tool that monkeys can use
光的粒子说(光电效应/康普顿效应)
黑体辐射初探
No&nbsp; result&nbsp; defined&amp; nbsp…
组件拆分实战
开口式霍尔电流传感器如何助力直流配电改造?
用Pycharm开发Flask框架设置debug模式没有效果的解决办法
Does the applet image component not display pictures?
机器人编程教育的市场竞争力
Chapter IX app project test (3) test tools
数字电路学习笔记(一)