Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

纪念我的第一道组合数

Posted by lmm333 at 2012-03-08 17:07:02 on Problem 2245
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator