Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int n, H, ok, v[105], sum[105], c[105], h[105], st[105], ap[105];
  7.  
  8. bool valid(int k)
  9. {
  10. if(ap[st[k]]>1)
  11. return 0;
  12. if(k>1 && c[st[k]]==c[st[k-1]])
  13. return 0;
  14. if(k>1 && h[st[k-1]]<h[st[k]])
  15. return 0;
  16. sum[k]=sum[k-1]+h[st[k]];
  17. if(sum[k]>H)
  18. return 0;
  19. if(k>n)
  20. return 0;
  21. return 1;
  22. }
  23.  
  24. void bkt(int k)
  25. {
  26. for(int x=1; x<=n; x++)
  27. {
  28. if(ap[x]==0)
  29. {
  30. st[k]=x;
  31. ap[st[k]]++;
  32. if(valid(k))
  33. {
  34. if(sum[k]==H)
  35. {
  36. for(int i=1; i<=k; i++)
  37. printf("%d ", st[i]);
  38. printf("\n");
  39. }
  40. else
  41. {
  42. if(k<n)
  43. bkt(k+1);
  44. }
  45. }
  46. ap[st[k]]--;
  47. }
  48. }
  49. }
  50.  
  51. int main()
  52. {
  53. freopen("pc.in", "r", stdin);
  54. freopen("pc.out", "w", stdout);
  55. scanf("%d%d", &n, &H);
  56. for(int i=1; i<=n; i++)
  57. scanf("%d%d", &h[i], &c[i]);
  58. bkt(1);
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement