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

光的粒子说(光电效应/康普顿效应)

Detailed explanation of iptables firewall rules and firewalld firewall rules

Does the applet image component not display pictures?

STM32 peripheral SDIO and SD card configuration

sqlserver 数据库之事物使用入门 案例

可扩展存储系统(上)

Resource management, high availability and automation (Part 2)

电学基础知识整理(一)
![[graduation season] graduate summary](/img/f6/59134c1dbf70fc809652d925fd528f.jpg)
[graduation season] graduate summary

STM32外设SDIO和SD卡的配置
随机推荐
数组的方法
leetcode:单调栈结构(进阶)
继承
资源管理、高可用与自动化(中)
A preliminary study of blackbody radiation
INFO:&nbsp; HHH000397:&nbsp; Using…
第一个.net core MVC项目
小程序image组件不显示图片?
Does the applet image component not display pictures?
黑体辐射初探
多线程与高并发四:VarHandle与强软弱虚引用和ThreadLocal
Door level modeling - learning notes
数据库系列之MySQL配置F5负载均衡
解析STEAM教育框架下未来教师研究能力
音频 scipy 中 spectrogram 的运作机制
Paging query optimization in MySQL of database Series
django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
多线程与高并发六:线程池源码解析
从遇见大咖到成为大咖,昇腾AI开发者创享日给开发者带来无限可能
Chapter 14 AC-DC power supply front stage circuit note I