problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::maximum_number_of_achievable_transfer_requests::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int maximumRequests (int n, vector< vector< int > > &requests)
 

详细描述

在文件 leetcode.h1417 行定义.

成员函数说明

◆ maximumRequests()

int leetcode::maximum_number_of_achievable_transfer_requests::Solution::maximumRequests ( int  n,
vector< vector< int > > &  requests 
)
static

在文件 leetcode.cpp3676 行定义.

3676 {
3677 int ans = 0;
3678 for(unsigned int i = 0; i < 1 << requests.size(); i++) {
3679 auto *in = new int[n];
3680 auto *out = new int[n];
3681 memset(in, 0, n * sizeof(int));
3682 memset(out, 0, n * sizeof(int));
3683 for(unsigned int j = 0; j < requests.size(); j++) {
3684 if((i & 1 << j) != 0) {
3685 out[requests[j][0]]++;
3686 in[requests[j][1]]++;
3687 }
3688 }
3689 bool ok = true;
3690 for(int j = 0; j < n; j++) {
3691 if(out[j] != in[j]) {
3692 ok = false;
3693 break;
3694 }
3695 }
3696 if(ok) {
3697 ans = max(ans, popcount(i));
3698 }
3699 delete[] in;
3700 delete[] out;
3701 }
3702 return ans;
3703 }

被这些函数引用 leetcode::maximum_number_of_achievable_transfer_requests::TEST().


该类的文档由以下文件生成: