dar0m! 2019. 9. 4. 00:42
μ‹œκ°„ μ œν•œ λ©”λͺ¨λ¦¬ μ œν•œ μ •λ‹΅ λΉ„μœ¨
1 초 128 MB 53.637 %



 

6603번: 둜또

문제 독일 λ‘œλ˜λŠ” {1, 2, ..., 49}μ—μ„œ 수 6개λ₯Ό κ³ λ₯Έλ‹€. 둜또 번호λ₯Ό μ„ νƒν•˜λŠ”λ° μ‚¬μš©λ˜λŠ” κ°€μž₯ 유λͺ…ν•œ μ „λž΅μ€ 49κ°€μ§€ 수 쀑 k(k>6)개의 수λ₯Ό 골라 μ§‘ν•© Sλ₯Ό λ§Œλ“  λ‹€μŒ κ·Έ 수만 κ°€μ§€κ³  번호λ₯Ό μ„ νƒν•˜λŠ” 것이닀. 예λ₯Ό λ“€μ–΄, k=8, S={1,2,3,5,8,13,21,34}인 경우 이 μ§‘ν•© Sμ—μ„œ 수λ₯Ό κ³ λ₯Ό 수 μžˆλŠ” 경우의 μˆ˜λŠ” 총 28가지이닀. ([1,2,3,5,8,13], [1,2,3,5,8,21], [1,2,3,5,8,34], [1,2

www.acmicpc.net

 

k 개둜 이루어진 μ§‘ν•© S μ—μ„œ 6개의 숫자λ₯Ό μ‚¬μ „μ‹μœΌλ‘œ 좜λ ₯ν•˜λ©΄ λœλ‹€.

 

λ©”λͺ¨λ¦¬ μ‹œκ°„
1116 KB 0 ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int k;
int S[15], chk[15];
void lotto(int position, int cnt) {
    if (cnt >= 6) {
        for (int i = 0; i < k; i++) {
            if (chk[i]) {
                printf("%d ", S[i]);
            }
        }
        printf("\n");
        return;
    }
    for (int i = position; i < k; i++) {
        if (!chk[i]) {
            chk[i] = 1;
            lotto(i, cnt + 1);
            chk[i] = 0;
        }
    }
    return;
}
 
int main() {
 
    while(1){
        scanf("%d"&k);
        if (k <= 0break;
 
        for (int i = 0; i < k; i++) {
            scanf("%d"&S[i]);
        }
 
        lotto(00);
 
        memset(S, 0sizeof(S));
        memset(chk, 0sizeof(chk));
        printf("\n");
    }
    return 0;
}
cs