Advertisement
Guest User

Untitled

a guest
May 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4. #define MM 10
  5. #define MK 30
  6.  
  7. int N, M, K;
  8. int a[MK], b[MK], c[MK];
  9. int rst, tmp;
  10.  
  11. int s[MM];
  12. void DFS(int i)
  13. {
  14. if (i == K)
  15. {
  16. rst = max(rst, tmp);
  17. return;
  18. }
  19. bool flag = true;
  20. for (int j = a[i]; j <= b[i]-1; j++)
  21. {
  22. if (s[j] + c[i] > N) flag = false;
  23. }
  24.  
  25. if (flag)
  26. {
  27. for (int j = a[i]; j <= b[i] - 1; j++) s[j] += c[i];
  28. tmp += (b[i] - a[i])*c[i];
  29. DFS(i + 1);
  30. for (int j = a[i]; j <= b[i] - 1; j++) s[j] -= c[i];
  31. tmp -= (b[i] - a[i])*c[i];
  32. }
  33.  
  34. DFS(i + 1);
  35. }
  36.  
  37. int main(void)
  38. {
  39. while (scanf("%d%d%d", &N, &M, &K))
  40. {
  41. if (N == 0 && M == 0 && K == 0) return 0;
  42.  
  43. for (int i = 0; i < K; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]);
  44.  
  45. rst = 0;
  46. DFS(0);
  47. printf("%d\n", rst);
  48. }
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement