本文主要是介绍使用STL输出组合序列 + UVa 441 Lotto,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=382
/*0.009s*/#include<bits/stdc++.h>
using namespace std;
const int mx = 15;int a[15];
bool ok[15];/*
输出从n个数中选m个数的组合字典序
以n=7,m=3为例
首先构造ok=1110000
然后ok的前一个排列为1101000
再前一个排列为1100100...1100001
然后是1011000...直到0000111
*/
void printfC(int n, int m)
{int i;for (i = 0; i < m; ++i) ok[i] = true;for (; i < n; ++i) ok[i] = false;do{for (i = 0; i < n; ++i)if (ok[i]) {printf("%d", a[i]); break;}for (++i; i < n; ++i)if (ok[i]) printf(" %d", a[i]);putchar(10);}while (prev_permutation(ok, ok + n));
}int main()
{int n, i;bool ok = false;while (scanf("%d", &n), n){if (ok) putchar(10);else ok = true;for (i = 0; i < n; ++i) scanf("%d", &a[i]);printfC(n, 6);}return 0;
}
这篇关于使用STL输出组合序列 + UVa 441 Lotto的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!