Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.9 kB
3
Indexable
Never
//Advertisement Schedule   
#include <iostream>
using namespace std;

int T, N, L[4], P[4], str[55], timead[55], strad[4], endad[4], maxdiem;
int visit[55];

void reset(){
	for(int i=1;i<=49;i++){
		visit[i]=0;
	}
	for(int i=1;i<=3;i++){
		strad[i] = endad[i] = 0;
	}

}


int tinhdiem(){
	int tongdiem = 0, diemxet;

	for(int i=1;i<=N;i++){
		diemxet = 0;
		if( strad[1] >= str[i] && endad[1] <= str[i]+timead[i]-1){
			diemxet = diemxet < P[1] ? P[1] : diemxet;
		}
		if( strad[2] >= str[i] && endad[2] <= str[i]+timead[i]-1){
			diemxet = diemxet < P[2] ? P[2] : diemxet;
		}
		if( strad[3] >= str[i] && endad[3] <= str[i]+timead[i]-1){
			diemxet = diemxet < P[3] ? P[3] : diemxet;
		}
		tongdiem+=diemxet;
	}
	return tongdiem;
}

bool checktimead(int i, int step){
	for(int j=i; j<i+L[step];j++){
		if(visit[j]!=0){
			return false;
		}
	}
	return true;
}

void BT(int step){
	if(step>3){
		int tongdiem = tinhdiem();
		if(tongdiem > maxdiem){

			/*for (int i=1; i<=50; ++i) {
				cout << visit[i] << " ";
			}
			cout << endl;
			cout << "==>" << endl;
			cout << tongdiem << endl;
			*/
			maxdiem = tongdiem; 
		}
		return;
	}

	for(int i=1;i<=49;i++){
		if( checktimead(i, step) /*&&  i+L[step]-1<=49*/){
			for(int j=i; j<i+L[step];j++){
				visit[j]=step;
			}
			strad[step]=i;
			endad[step]=i+L[step]-1;
			BT(step+1);
			for(int j=i; j<i+L[step];j++){
				visit[j]=0;
			}
			strad[step]=0;
			endad[step]=0;
		}

	}
}



int main(){
	freopen("quangcao.txt", "r" , stdin);
	cin>>T;
	for(int t=1;t<=T;t++){
		cin>>N>>L[1]>>L[2]>>L[3]>>P[1]>>P[2]>>P[3];
		reset();
		//cout<<N<<" "<<L[1]<<" "<<L[2]<<" "<<L[3]<<" "<<P[1]<<" "<<P[2]<<" "<<P[3]<<endl;
		for(int i=1;i<=N;i++){
			cin>>str[i]>>timead[i];
			//cout<<str[i]<<" "<<timead[i]<<endl;
		}
		maxdiem = 0;
		BT(1);
		cout<<"Case #"<<t<<endl<<maxdiem<<endl;
	}
	return 0;
}
Leave a Comment