| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
纪念我的第一道组合数int a[15];
int out[10];
int n, m;
void cmb(int dep, int pos) {//dep剩余的个数(层数) pos位置
if (pos > n || pos + dep > n)
return;
if (dep == 0) {
for (int i = 0; i < m - 1; ++i) {
printf("%d ", out[i]);
}
printf("%d\n", out[m - 1]);
return;
}
out[m - dep] = a[pos];
cmb(dep - 1, pos + 1); //选pos位置的数字
cmb(dep, pos + 1); //不选
}
int main() {
while (scanf("%d", &n)) {
if (!n)
return 0;
for (int i = 0; i < n; ++i)
scanf("%d", a + i);
sort(a, a + n);
m = 6;
cmb(6, 0);
puts("");
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator