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
| #include<bits/stdc++.h> using namespace std; int mat[11][1500][1500]; int m; void dfs(int now, int l, int m, int one[], int neone[]) { int len = pow(2, now - m), lem = pow(2, m),nl; for (int i = 1; i <= lem; i++) { nl = 1; for (int j = 1; j <= lem; j++) { if (mat[m][i][j] == 1) { for (int k = 0; k < len; k++) { mat[now][l + i - 1][nl++] = one[k]; } } else { for (int k = 0; k < len; k++) { mat[now][l + i - 1][nl++] = neone[k]; } } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> m; int k = 0; while (m!=1) { k++; m /= 2; } m = k; mat[1][1][1] = mat[1][1][2] = mat[1][2][1] = 1, mat[1][2][2] = -1; for (int i = 2; i < 11; i++) { for (int j = 1; j <= pow(2, i); j++) { mat[i][1][j] = 1; } for (int j = 1; j <= pow(2, i - 1); j++) { mat[i][2][j] = 1; } for (int j = pow(2, i - 1) + 1; j <= pow(2, i); j++) { mat[i][2][j] = -1; } int tmp = 2, one[1500], neone[1500]; for (int j = 1; j < i; j++) { for (int k = 0; k < pow(2, i - j - 1); k++) { one[k] = 1; neone[k] = -1; } for (int k = pow(2, i - j - 1); k < pow(2, i - j); k++) { one[k] = -1; neone[k] = 1; } dfs(i, tmp + 1, j, one, neone); tmp += pow(2, j); } } for(int i = 1; i <= pow(2, m); i++) { for (int j = 1; j <= pow(2, m); j++) { cout << mat[m][i][j] << " \n"[j == pow(2, m)]; } } }
|