excel 排列组合公式?

excel 排列组合公式?,第1张

Excel有排列组合公式,PERMUT为排列函数,COMBIN为组合函数。

1、电脑打开Excel表格,输入组合函数=COMBIN(50,3)。

2、回车就会得到19600。

3、输入排列公式=PERMUT(50,3)/PERMUT(3,3)。

4、回车就可以了。

和结果之后就是str,str strlen(str)的值以及next_permutation(a,b)的意义和结果最后while判断 把str字符串排列组合 然后放回str字符串 跑一下下面

#include<iostream>

#include<algorithm>

#include<string>

using namespace std;

int main()

{

    string s="0000011111";

    sort(sbegin(),send());

    while(next_permutation(sbegin(),send()))

        cout<<s<<endl;

}

C++的next_permutation 十分好用,自己写用递归,怎么也无法去重。

#include<iostream>

#include<algorithm>

#include<mathh>

using namespace std;

void main(){

int m,n,a[100],i;

cout<<"输入n和m:"<<endl;

cin>>n>>m;

for(i=0;i<n;i++){

cin>>a[i];

}

do{

copy(a,a+m,ostream_iterator<int>(cout,"\t"));

cout<<endl;

}while(next_permutation(a,a+n));

}

我用的stl库函数,这个应该是最简单的!!!虽然网上有很多递归的方法!!!其次,如果要运行,至少得vc60的企业版!!!

●首先sort要包含algorithm头文件。

●其次sort是std命名空间中的函数,要写std::sort,或者在最开始写using namespace std;

●最后,C++中的sort很多情况下不需要你写cmp函数,像你的情况是比较两个int,可以直接这么写:

sort(a+j,a+n-j+1);

sort自己知道如何比较两个int的。而且即使是复杂的比较,也一般写仿函数而不是函数,因为仿函数更快。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/13494795.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2025-09-01
下一篇2025-09-01

发表评论

登录后才能评论

评论列表(0条)

    保存