STL next_permutation(a,a+n) 生成一个序列的全排列。满足可重集。
/** 题目: 链接: 题意: 思路: */ #include <iostream> #include <cstdio> #include <vector> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long LL; const int mod=1e9+7; const int maxn=1e2+5; const double eps = 1e-12; int main() { int a[5] = {0,1,2,2,3}; int n = 5; sort(a,a+n); int cnt = 0; do{ for(int i = 0; i < n; i++){ printf("%d%s",a[i],i==n-1?"\n":" "); } cnt++; }while(next_permutation(a,a+n)); cout<<"num = "<<cnt<<endl;/// 5!/2! = 3*4*5 = 60; return 0; }
posted on 2017-05-24 12:36 hnust_accqx 阅读(454) 评论(0) 编辑 收藏 举报