Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- #define MM 10
- #define MK 30
- int N, M, K;
- int a[MK], b[MK], c[MK];
- int rst, tmp;
- int s[MM];
- void DFS(int i)
- {
- if (i == K)
- {
- rst = max(rst, tmp);
- return;
- }
- bool flag = true;
- for (int j = a[i]; j <= b[i]-1; j++)
- {
- if (s[j] + c[i] > N) flag = false;
- }
- if (flag)
- {
- for (int j = a[i]; j <= b[i] - 1; j++) s[j] += c[i];
- tmp += (b[i] - a[i])*c[i];
- DFS(i + 1);
- for (int j = a[i]; j <= b[i] - 1; j++) s[j] -= c[i];
- tmp -= (b[i] - a[i])*c[i];
- }
- DFS(i + 1);
- }
- int main(void)
- {
- while (scanf("%d%d%d", &N, &M, &K))
- {
- if (N == 0 && M == 0 && K == 0) return 0;
- for (int i = 0; i < K; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]);
- rst = 0;
- DFS(0);
- printf("%d\n", rst);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement