fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdbool.h>
  4.  
  5. #define MAXN 13
  6. #define MAX_MASK 8192
  7. #define setbit(x, i) ((x) | (1 << (i)))
  8. #define resetbit(x, i) ((x) & (~(1 << (i))))
  9.  
  10. int next[MAX_MASK][MAXN]; /// next[bitmask][cur] = next lis mask when the current lis mask is bitmask and cur is added to the end
  11.  
  12. void Generate(){
  13. int i, cur, res, bitmask;
  14. memset(next, -1, sizeof(next));
  15.  
  16. for (bitmask = 0; bitmask < MAX_MASK; bitmask++){
  17. for (cur = 0; cur < MAXN; cur++){
  18. if (bitmask == 0) next[bitmask][cur] = 1 << cur;
  19. else{
  20. res = setbit(bitmask, cur);
  21. for (i = cur + 1; i < MAXN; i++){ /// Find the smallest number (if there are any) with a set bit greater than cur and reset it
  22. if (bitmask & (1 << i)){
  23. res = resetbit(res, i);
  24. break;
  25. }
  26. }
  27. next[bitmask][cur] = res;
  28. }
  29. }
  30. }
  31. }
  32.  
  33. int main(){
  34. Generate();
  35. }
  36.  
Success #stdin #stdout 0s 2572KB
stdin
Standard input is empty
stdout
Standard output is empty