Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. // READING INPUT
  6. #define SCD(t) fscanf(stdin, "%d",&t)
  7.  
  8. // Offset Arrays
  9. const int fx[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};
  10.  
  11. class Answer {
  12. public:
  13. char ans[5][17][17][17][17][17];
  14. };
  15.  
  16. int main() {
  17. Answer* a = new Answer();
  18. for (int i = 0; i < 5; i++) {
  19. for (int j = 0; j < 17; j++) {
  20. for (int k = 0; k < 17; k++) {
  21. for (int x = 0; x < 17; x++) {
  22. for (int y = 0; y < 17; y++) {
  23. for (int z = 0; z < 17; z++) {
  24. a->ans[i][j][k][x][y][z] = 0;
  25. }
  26. }
  27. }
  28. }
  29. }
  30. }
  31. for (int n = 1; n < 5; n++) {
  32. int ans = 0;
  33. for(int i = 0; i < (1 << (n * n)); i++) {
  34.  
  35. int grid[n][n];
  36. for (int j = 0; j < n; j++) {
  37. for (int k = 0; k < n; k++) {
  38. grid[j][k] = 0;
  39. }
  40. }
  41. for (int j = 0; j < n * n; j++) {
  42. if ((i & (1 << j)) != 0) grid[j / n][j % n] = 1;
  43. }
  44. int arr[5] = {0};
  45. for (int j = 0; j < 5; j++) arr[j] = 0;
  46. for (int j = 0; j < n; j++) {
  47. for (int k = 0; k < n; k++) {
  48. int ctr = 0;
  49. if (grid[j][k]) {
  50. for (int l = 0; l < 4; l++) {
  51. int nextR = j + fx[l][0];
  52. int nextC = k + fx[l][1];
  53. if (nextR >= 0 && nextR < n && nextC >= 0 && nextC < n) {
  54. if (grid[nextR][nextC]) ctr++;
  55. }
  56. }
  57. if (ctr <= 4) arr[ctr]++;
  58. }
  59.  
  60. }
  61. }
  62. int v = arr[0];
  63. int w = arr[1];
  64. int x = arr[2];
  65. int y = arr[3];
  66. int z = arr[4];
  67. a->ans[n][v][w][x][y][z]++;
  68. }
  69. }
  70. int t;
  71. SCD(t);
  72. while (t--) {
  73. int n;
  74. SCD(n);
  75. int c0, c1, c2, c3, c4;
  76. SCD(c0);
  77. SCD(c1);
  78. SCD(c2);
  79. SCD(c3);
  80. SCD(c4);
  81. fprintf(stdout, "%d\n", a->ans[n][c0][c1][c2][c3][c4]);
  82. }
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement