当前位置: 首页 > news >正文

Property Booking Optimizer

Given:

  • A list of properties where each property has (id, neighborhood, capacity)
  • A group size (number of people that need accommodation)
  • A target neighborhood

Goal:
Find the optimal combination of properties in the given neighborhood that can accommodate the group with these rules:

  1. Total capacity must be >= group size
  2. Choose the combination with minimum total capacity that exceeds group size
  3. If multiple combinations have same capacity, choose the one with fewer properties
  4. If no valid combination exists, return empty list

Examples:

Example 1:
Properties:

  • (1, "area1", 5)
  • (2, "area1", 3)
  • (3, "area1", 2)
  • (4, "area2", 4)
    GroupSize = 5, neighborhood = "area1"
    Output: [1] // Property 1 alone has capacity 5, which is optimal

Example 2:
Same properties, GroupSize = 6, neighborhood = "area1"
Output: [1, 3] // Properties 1+3 give capacity 7, which is minimal solution

Example 3:
Properties:

  • (1, "area1", 5)
  • (2, "area1", 3)
    GroupSize = 10, neighborhood = "area1"
    Output: [] // No combination can accommodate 10 people
 1 def optimize_booking(properties, group_size, target_neighborhood):
 2     """
 3     Finds the optimal combination of properties to accommodate a group.
 4     
 5     Args:
 6         properties: List of (id, neighborhood, capacity)
 7         group_size: Minimum capacity required
 8         target_neighborhood: The neighborhood to search in
 9         
10     Returns:
11         List of property IDs or [] if no valid combination exists.
12     """
13     # 1. Filter properties by neighborhood
14     filtered = [p for p in properties if p[1] == target_neighborhood]
15     
16     if not filtered:
17         return []
18 
19     # 2. DP table: dp[total_capacity] = (property_count, list_of_ids)
20     # We use a dictionary to store the best (minimum property count) combination for every possible capacity sum.
21     dp = {0: (0, [])}
22     
23     for p_id, neighborhood, cap in filtered:
24         new_entries = {}
25         for current_cap, (count, ids) in dp.items():
26             new_cap = current_cap + cap
27             new_count = count + 1
28             new_ids = ids + [p_id]
29             
30             # Update only if this capacity hasn't been reached yet, 
31             # or if we found a way to reach it with fewer properties.
32             if new_cap not in dp or new_count < dp[new_cap][0]:
33                 if new_cap not in new_entries or new_count < new_entries[new_cap][0]:
34                     new_entries[new_cap] = (new_count, new_ids)
35         
36         dp.update(new_entries)
37     
38     # 3. Filter combinations that satisfy the group size
39     candidates = {cap: info for cap, info in dp.items() if cap >= group_size}
40     
41     if not candidates:
42         return []
43     
44     # 4. Find the minimum total capacity
45     min_cap = min(candidates.keys())
46     
47     # 5. Return the IDs (sorted for consistency)
48     best_combination_ids = candidates[min_cap][1]
49     return sorted(best_combination_ids)
50 
51 # --- Test Examples ---
52 properties = [
53     (1, "area1", 5),
54     (2, "area1", 3),
55     (3, "area1", 2),
56     (4, "area2", 4)
57 ]
58 
59 # Example 1: GS = 5, area1 -> Expected [1]
60 print(f"Example 1: {optimize_booking(properties, 5, 'area1')}")
61 
62 # Example 2: GS = 6, area1 -> Expected [1, 3] (Cap 7 is min, 1+3 is better than 1+2 because both are same cap)
63 print(f"Example 2: {optimize_booking(properties, 6, 'area1')}")
64 
65 # Example 3: GS = 10, area1 -> Expected []
66 print(f"Example 3: {optimize_booking(properties, 10, 'area1')}")

 

http://www.jsqmd.com/news/485477/

相关文章:

  • 2026深圳驾校权威榜单出炉!10家正规机构推荐,拿证快服务好 - 深度智识库
  • 新西兰移民,真正的差距不在政策,而在机构理解深度——2026国内移民新西兰机构排行 - 看ES
  • 2026年 静音木门厂家推荐排行榜:专业静噪入户门、静噪铝木门品牌深度解析,打造宁静家居首选 - 品牌企业推荐师(官方)
  • 2026新西兰移民机构推荐:海华熙瑞带你解锁新西兰“永久回头签” - 看ES
  • 揭秘扬州母婴护理服务靠谱品牌,费用和服务都咋样? - 工业品网
  • 106短信平台哪家好?不同业务场景下的采购差异 - Qqinqin
  • 2026年山东靠谱化妆培训学校盘点,山东欧曼谛化妆培训学校上榜没 - 工业推荐榜
  • 重庆家庭装修公司服务选购指南,哪家性价比更高 - 工业推荐榜
  • 聊聊欧派装修公司价格,与重庆港宏装饰相比哪家性价比更高? - 工业设备
  • 硕士研究生如何建立个人知识体系
  • 分析2026年南昌口碑好的挺水植物供应商,价格怎么样 - 工业品网
  • 总结2026年哈尔滨欧米奇蛋糕培训费用,看看是否符合预算 - mypinpai
  • 陕西不锈钢雕塑常见问题解答(2026最新专家版) - 速递信息
  • 红外无人机目标检测数据集(4500+张图片已标注)| YOLO训练数据集 AI视觉检测
  • 《Learning to Model the World With Language》随记
  • 分析鸿犀GEO优化能提升多少效果,在南京性价比高吗 - myqiye
  • 2026年四川货运物流公司TOP5推荐:综合服务能力本土力量与专业深耕 - 深度智识库
  • 探寻慧友酒店集团专业吗,旗下酒店入住体验及周边配套大起底 - 工业推荐榜
  • 聊聊广州靠谱的GEO优化公司性价比哪家高 - 工业品牌热点
  • 深度解析2026 AIT全明星阵容:超声波清洗与制动系统精密的工业之美 - RF_RACER
  • 深聊山东欧曼谛美业学校在哪里,其摄影专业师资力量靠谱吗? - 工业设备
  • 2026年重庆短视频运营公司推荐,靠谱的都有哪些 - myqiye
  • 马克思主义在AI时代的理论创新与实践重构 ——基于《指月之手》的深度学术分析
  • 2026年驻马店全屋定制资深厂商排名,哪家性价比高值得推荐? - myqiye
  • 氢能检测赋能多行业:山东瑞能氢气电解池实用指南 - 品牌推荐大师
  • 2026想了解西安欧米奇学生管理严格吗,这所学校口碑值得关注 - mypinpai
  • 2026年口碑不错的短视频运营专业公司,重庆哪家服务好 - mypinpai
  • 鸿犀GEO优化价格多少,特点鲜明提升品牌知名度 - 工业品牌热点
  • 2026年北京成人学历教育品牌排名,北京泓云教育靠不靠谱? - 工业品牌热点
  • 2026年扬州月子中心机构费用大揭秘,哪家价格更合理 - 工业品网