-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathf.cpp
94 lines (89 loc) · 1.47 KB
/
f.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int N, K;
int ans[1000][1000];
int col[1000][20];
vector<int> cur, cnt;
int len = 1, n = 1;
void add(){
while(!cnt.empty()){
int x = cnt.back();
cnt.pop_back();
if(x != K-1){
x++;
cnt.push_back(x);
break;
}
}
if(cnt.empty()){
if(len == n){
len = 1;
n++;
cur.clear();
cur.push_back(n);
}else{
while(true){
int x = cur.back();
cur.pop_back();
if(cur.empty()){
len++;
cur.push_back(x);
for(int i = len-1; i >= 1; i--){
cur.push_back(i);
}
break;
}
x++;
if(x < cur.back()){
cur.push_back(x);
for(int i = len-cur.size(); i >= 1; i--){
cur.push_back(i);
}
break;
}
}
}
}
while(cnt.size() < len){
cnt.push_back(1);
}
}
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> N >> K;
cur.push_back(1);
cnt.push_back(1);
for(int i = 1; i < N; i++){
/*for(int j : cur){
moo << j << ' ';
}
moo << endl;
for(int j : cnt){
moo << j << ' ';
}
moo << endl << endl;*/
for(int j = 0; j < len; j++){
col[i][cur[j]] = cnt[j];
}
for(int j = 0; j < i; j++){
for(int k = 0; k < len; k++){
if(col[j][cur[k]] < cnt[k]){
ans[j][i] = cur[k];
break;
}
}
}
if(i != N-1) add();
}
moo << n << endl;
for(int i = 0; i < N; i++){
for(int j = i+1; j < N; j++){
moo << ans[i][j] << ' ';
}
}
moo << endl;
}