例题 :
假如小明入职公司,有面试官按照小明面试情况打分。 有n个面试官 ,每个人打出各自分数,然后不知道顺序,求有多少种打分的结果
例如:
n = 3
打分arr[] ={1 , 2 , 3};
最后得分的结果有6种;
n = 3
arr[] = {1 ,1 ,2}
最后得分结果有3种;
头文件 中有一个特别好用的 自动全排列计数并去重的函数
next_permutation(start ,end);完美解决
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n = 0;
cin >> n;
vector<int> * a = new vector<int>[n];
for (int i = 0 ; i < n ; ++i)
{
int temp = ' ';
cin >> temp;
a[i].push_back(temp);
}
int cnt = 0;
do { //输出
cnt++;
} while (next_permutation(a, a + n)); //全排列
cout << cnt << endl;
return 0;
}