当前位置:网站首页>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.
边栏推荐
- Research and arrangement of electronic map coordinate system
- 密码加密md5和加盐处理
- 如何修改SE38编辑器主题
- Chapter IX app project test (3) test tools
- Scalable storage system (I)
- How to write anti shake throttling for small programs?
- leetcode:494.数组中添加加减运算符得到指定值的所有方法
- ambari SSLError: Failed to connect. Please check openssl library versions.
- 一文告诉你什么是 Kubernetes
- 小程序的防抖节流怎么写?
猜你喜欢
随机推荐
第一个.net core MVC项目
Pycharm setting pseudo sublime color scheme
一文告诉你什么是 Kubernetes
English语法_形容词/副词3级-比较级_常用短语
多项目开发入门,基础设计 类库项目使用
English notes - cause and effect
Go 數據類型篇(四)之浮點型與複數類型
Extensible database (I)
Anaconda command usage
可扩展存储系统(上)
一千行 MySQL 学习笔记,值得收藏!
Li Kou daily question - day 29 -219 Duplicate Element II exists
用Pycharm开发Flask框架设置debug模式没有效果的解决办法
django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
力扣每日一题-第29天-1491.去掉最低工资和最高工资后的平均工资
密码加密md5和加盐处理
物体上下漂浮工具
ambari SSLError: Failed to connect. Please check openssl library versions.
"Five layer" architecture of cloud applications and services
Resource management, high availability and automation (medium)