1601. Maximum Number of Achievable Transfer Requests
We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.
All buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero. This means the number of employees leaving is equal to the number of employees moving in. For example if n = 3 and two employees are leaving building 0, one is leaving building 1, and one is leaving building 2, there should be two employees moving to building 0, one employee moving to building 1, and one employee moving to building 2.
Return the maximum number of achievable requests.
解题重点:
1. 数据总量不大,可以回溯+枚举
2. 数组 delta 记录每一栋楼的员工变化量,变量 cnt 记录被选择的请求数量。
3. 对于第pos 个请求 [x,y],如果选择该请求,那么就需要将 delta[x] 的值减 11, delta[y] 的值加 11,cnt 的值加 11
4. 修改 delta 的同时维护 delta 中的 0 的个数,记作zero,初始值为 n。如果 delta[x] 增加或减少前为 0,则将 zero 减 1;如果delta[x] 增加或减少后为 0,则将zero 加 1。
We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.
You are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to building toi.
All buildings are full, so a list of requests is achievable only if for each building, the net change in employee transfers is zero. This means the number of employees leaving is equal to the number of employees moving in. For example if n = 3 and two employees are leaving building 0, one is leaving building 1, and one is leaving building 2, there should be two employees moving to building 0, one employee moving to building 1, and one employee moving to building 2.
Return the maximum number of achievable requests.
解题重点:
1. 数据总量不大,可以回溯+枚举
2. 数组 delta 记录每一栋楼的员工变化量,变量 cnt 记录被选择的请求数量。
3. 对于第pos 个请求 [x,y],如果选择该请求,那么就需要将 delta[x] 的值减 11, delta[y] 的值加 11,cnt 的值加 11
4. 修改 delta 的同时维护 delta 中的 0 的个数,记作zero,初始值为 n。如果 delta[x] 增加或减少前为 0,则将 zero 减 1;如果delta[x] 增加或减少后为 0,则将zero 加 1。
#赫海[超话]# [ NEWS|NOW. ]
220128 NOW. 电台简介更新:
爱豆特辑2弹
今天和'fromis_9'一起吧~
新曲'DM' 1位
全曲上榜
初动打破自身的新纪录
最近最火的
fromis_9来参加DE Show了~?
迎来4周年的fromis_9!
时隔4个月超高速回归!
全专歌曲评价走起~
fromi们来了
不看舞蹈的话会很遗憾吧~~~
以零食Quiz为借口的
准备了舞蹈对决,,
支持fromis_9的粉丝们来这里!!
周五 下午5点DE Show
一起度过的话 不行嘛
翻译:唔西迪西
220128 NOW.
爱豆特辑2弹
今天和'fromis_9'一起吧~
新曲'DM' 1位
全曲上榜
初动打破自身的新纪录
最近最火的
fromis_9来参加DE Show了~?
迎来4周年的fromis_9!
时隔4个月超高速回归!
全专歌曲评价走起~
fromi们来了
不看舞蹈的话会很遗憾吧~~~
以零食Quiz为借口的
准备了舞蹈对决,,
支持fromis_9的粉丝们来这里!!
周五 下午5点DE Show
一起度过的话 不行嘛
翻译:唔西迪西
HYBE12月31日将举行联合演唱会...贾斯汀·比伯出演
HYBE方面12月7日宣布了Weverse Con [New Era]的举办消息。这是Weverse Con关闭一年后开始举办。 去年以首次亮相后,今年以扩张的方向性全新蜕变。
此次演出将通过线下和线上同时的方式进行,预计将有BUMZU、Dvwn、ENHYPEN、fromis_9、Justin Bieber、李贤、SEVENTEEN、TOMORROW X TOGETHER等艺人出演。 特别是贾斯汀•比伯的出演让人备受期待。
(cr newsen)
HYBE方面12月7日宣布了Weverse Con [New Era]的举办消息。这是Weverse Con关闭一年后开始举办。 去年以
此次演出将通过线下和线上同时的方式进行,预计将有BUMZU、Dvwn、ENHYPEN、fromis_9、Justin Bieber、李贤、SEVENTEEN、TOMORROW X TOGETHER等艺人出演。 特别是贾斯汀•比伯的出演让人备受期待。
(cr newsen)
✋热门推荐