Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
491 B
2
Indexable
Never
int n = indicators.size();
    int max_profit = 0;
 
    
    for (int i = 0; i < (1 << n); i++) {
        int current_or = 0;
        int current_profit = 0;
 
        
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                current_profit += profit[j];
                current_or |= weights[j];
            }
        }
 
        
        if (current_or <= k) {
            max_profit = max(max_profit, current_profit);
        }
    }
 
    cout<< max_profit;
Leave a Comment