Advertisement
STANAANDREY

squares tp

Nov 7th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #define NMAX 101
  4. int sides[NMAX], n, p;
  5. bool used[NMAX][NMAX];
  6.  
  7. bool isValid(int line, int col, int side) {
  8.   if (side + line >= n || side + col >= n) {
  9.     return false;
  10.   }
  11.   for (int i = line; i < line + side; i++) {
  12.     for (int j = col; j < col + side; j++) {
  13.       if (used[i][j]) {
  14.     return false;
  15.       }
  16.     }
  17.   }
  18.   return true;
  19. }
  20.  
  21. void setSquare(int line, int col, int side, bool val) {
  22.   for (int i = line; i < line + side; i++) {
  23.     for (int j = col; j < col + side; j++) {
  24.       used[i][j] = val;
  25.     }
  26.   }
  27. }
  28.  
  29. bool isSol() {
  30.   bool ok = true;
  31.   for (int i = 0; i < n; i++) {
  32.     for (int j = 0; j < n; j++) {
  33.       ok &= used[i][j];
  34.     }
  35.   }
  36.   return ok;
  37. }
  38.  
  39. void bktr(int top) {
  40.   for (int i = 0; i < n; i++) {
  41.     for (int line = 0; line < n; line++) {
  42.       for (int col = 0; col < n; col++) {
  43.     if (isValid(line, col, sides[i])) {
  44.       setSquare(line, col, sides[i], true);
  45.       if (isSol()) {
  46.        
  47.       } else {
  48.        
  49.       }
  50.     }
  51.       }
  52.     }
  53.   }
  54. }
  55.  
  56. int main(void) {
  57.   int n;
  58.   scanf("%d", &n);
  59.   for (int i = 0; i < n; i++) {
  60.     scanf("%d", sides + i);
  61.   }
  62.   scanf("%d", &p);
  63.   return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement