Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <windows.h>
- using namespace std;
- int optMark ;
- bool cur[5] ,optimal[5];
- bool checkOptimal( int curMark ){
- return ( curMark > optMark );
- }
- void BT(int curV , int curTime , int curMark , int fullTime , int time[] , int mark[] ){
- if( curTime + time[ curV ] <= fullTime ){
- /// --- ADD THIS VALUE TO ANSWER --- ///
- cur[ curV ] = true;
- if( curV < 4 ){
- BT( curV+1 , curTime+time[curV] , curMark+mark[curV] , fullTime , time , mark );
- }else if (curV == 4){
- if( checkOptimal( curMark ) ){
- optMark = curMark;
- for( int i=0 ; i<5 ; i++)
- optimal[i] = cur[i];
- }
- }
- cur[ curV ] = false;
- /// --- TRY WITHOUT ADD THIS VALUE TO ANSWER --- ///
- if( curV < 4 ){
- BT( curV+1 , curTime , curMark , fullTime , time , mark );
- }else if (curV == 4){
- if( checkOptimal( curMark ) ){
- optMark = curMark;
- for( int i=0 ; i<5 ; i++)
- optimal[i] = cur[i];
- }
- }
- }
- else if( curTime + time[ curV ] > fullTime ){
- if( curV < 4 ){
- BT( curV+1 , curTime , curMark , fullTime , time , mark );
- }else if (curV == 4){
- if( checkOptimal( curMark ) ){
- optMark = curMark;
- for( int i=0 ; i<5 ; i++)
- optimal[i] = cur[i];
- }
- }
- }
- }
- int main(){
- int time[5] = { 15 ,10 , 5, 20 , 5 };
- int mark[5] = { 10 ,10 ,10, 30 ,15};
- BT( 0 , 0 , 0 , 30 , time , mark );
- cout << "Optimal Mark Solution = " << optMark << endl;
- for(int i=0 ; i<5 ; i++){
- cout << " " << optimal[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement