#include<iostream>
using namespace std;
int L[4], P[4]; // luu do dai va diem so
int A[55], D[55]; // arrival va duration
int T;
int N;
int maxpoint;
void backtrack(int ad_idx,int t1, int t2, int t3) {
	if(ad_idx >3) {
		int end1 = t1 + L[1];
		int end2 = t2 + L[2];
		int end3 = t3 + L[3];
		int total = 0;
		for(int i=1; i<=N; i++) {
			int start = A[i];
			int end = A[i] + D[i];
			int point = 0;
			if( start <= t1 && end1 <= end) {
				if(P[1] > point) {
					point = P[1];
				}
			}
			if( start <= t2 && end2 <= end) {
				if(P[2] > point) {
					point = P[2];
				}
			}
			if( start <= t3 && end3 <= end) {
				if(P[3] > point) {
					point = P[3];
				}
			}
			total += point;
		}
		if(total > maxpoint) {
			maxpoint = total;
		}
	}
	for(int t = 0; t<=50; t++) {
		int e = t + L[ad_idx];
		if(ad_idx == 2 && !(e <= t1 || t >= t1+L[1])) continue;
		if(ad_idx == 3 && (!(e <= t1 || t >= t1+L[1]) || !(e <= t2 || t >= t2+L[2]) )) continue;
		if(ad_idx == 1) backtrack(2,t,0,0);
		else if(ad_idx==2) backtrack(3,t1,t,0);
		else if(ad_idx==3) backtrack(4,t1,t2,t);
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	cin >> T;
	for(int tc = 1; tc <= T; tc++) {
		cin >> N >> L[1] >> L[2] >> L[3] >> P[1] >> P[2] >> P[3];
		for(int i = 1; i<=N;i++) {
			cin >> A[i] >> D[i];
		}
		int K[6][3] = {
			{1,2,3} , {1,3,2},
			{2,1,3} , {2,3,1},
			{3,1,2} , {3, 2, 1}
		};
		maxpoint = 0;
		backtrack(1,0,0,0);
		cout << "Case" << " " << "#" << tc << endl << maxpoint << endl;
	}
	return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: