weinan030416

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

排列问题

有n个人排成一队散步,第二天每个人都不想和前一天前面的人相同,多少种排列

n!-(n-1)(n-1)!+(n-2)(n-2)!-...1*1

模拟n=3

复制代码
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;

int main()
{
    for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
    for(int k=1;k<=3;k++)
    {
        if(i==j||i==k||j==k||i==j-1||j==k-1)    continue;
        else
        cout<<i<<" "<<j<<" "<<k<<endl;
    }
    
    return 0;
}
复制代码

组合数

复制代码
#include<bits/stdc++.h>
using namespace std;

int calc(int n,int m)
{
    if(m==1)
    return n;
    if(n==0)
    return 0;
    return calc(n-1,m-1)+calc(n-1,m);
}

//从n个物品里面取走m个 
int main()
{
    int n,m;
    cin>>n>>m;
    cout<<calc(n,m);
    return 0;
}
复制代码

 

posted on   楠030416  阅读(25)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示