内容中心

返回列表
2026年质量好的常熟印花水刺无纺布厂家选购参考建议-常熟市永得利水刺无纺布有限公司
2026-03-04 09:02:21
常熟市永得利水刺无纺布有限公司成立于 2007 年,公司坐落于“中国非织 造布及设备名镇”江苏省常熟市支塘镇,是一家专业从事水刺无纺布生产和无纺布深加工的技术企业,为江苏省专精特新中小企业,通过 质量管理体系认证,并在江苏省股权交易中心科技创新板挂牌。 永得利的主要产品有本白、印花、染色、上浆水刺无纺布和功能性水刺无纺 布。所有产品均可由客户定制。 公司产品被应用到医疗卫生、美容护肤、汽车内外饰、电子配件、过滤和工业资材等多个领域,永得利始终致力于水刺无纺布的开发与生产,通过自主创新获得20多项专 利,并获得中国纺织工业联合会科学技术二等奖和江苏省研究生工作站等荣誉。

To solve this problem, we need to find the minimum number of coins required to make a given target amount using a set of coin denominations. This is a classic problem that can be efficiently solved using Dijkstra's Algorithm (or BFS, since each coin adds exactly one to the count of coins used). Here, we use Dijkstra's Algorithm to prioritize states with fewer coins, ensuring we find the minimal solution first.

Approach

  1. Problem Analysis: We need to reach the target sum using the least number of coins. Each coin can be used multiple times (unbounded knapsack variant).
  2. Intuition: Use a priority queue (min-heap) to always expand the state with the fewest coins first. This ensures that the first time we reach the target sum, it's with the minimal number of coins.
  3. Optimization: Track the minimal number of coins needed to reach each sum using a visited array. This avoids reprocessing states with higher or equal coin counts.

Solution Code

import heapq

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr +=1
    coins = list(map(int, input[ptr:ptr+N]))
    ptr +=N
    T = int(input[ptr])

    INF = float('inf')
    visited = [INF]*(T+1)
    heap = []
    heapq.heappush(heap, (0,0))  # (number of coins, current sum)
    visited[0] = 0

    while heap:
        count, current = heapq.heappop(heap)
        if current == T:
            print(count)
            return
        for coin in coins:
            next_sum = current + coin
            if next_sum > T:
                continue
            if visited[next_sum] > count + 1:
                visited[next_sum] = count + 1
                heapq.heappush(heap, (count+1, next_sum))
    print(-1)  # If target can't be reached

if __name__ == "__main__":
    main()

Explanation

  1. Initialization:
    • visited array: Stores the minimal coins needed to reach each sum (initialized to infinity, except sum 0 which uses 0 coins).
    • Priority queue: Starts with the state (0 coins, sum=0).
  2. Processing:
    • Pop the state with the fewest coins from the heap.
    • If the current sum equals the target, return the count of coins (since it's the minimal).
    • For each coin, compute the new sum. If the new sum is within the target and the new coin count is better (fewer) than the existing value in visited, update visited and push the new state to the heap.
  3. Result: If the heap is exhausted without reaching the target, return -1 (target can't be formed with given coins).

This approach efficiently finds the minimal coins using Dijkstra's Algorithm, ensuring optimal performance even for larger target values. The time complexity is O(T * log T) (due to heap operations), which is feasible for most practical cases. For even better performance (O(T)), BFS can be used since each step adds exactly one coin (level order traversal gives minimal coins first). However, the given solution is correct and works well for the problem.

常熟市永得利水刺无纺布有限公司

常熟市永得利水刺无纺布有限公司



(免责声明:本文为本网站出于传播商业信息之目的进行转载发布,不代表本网站的观点及立场。本文所涉文、图、音视频等资料的一切权利和法律责任归材料提供方所有和承担。本网站对此资讯文字、图片等所有信息的真实性不作任何保证或承诺,亦不构成任何购买、投资等建议,据此操作者风险自担。) 本文为转载内容,授权事宜请联系原著作权人,如有侵权,请联系本网进行删除。

点击呼叫(详情介绍)
在线客服

在线留言
您好,很高兴为您服务,可以留下您的电话或微信吗?