多重揹包問題,並使用二進制分物品.
/*Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14301 Accepted: 4836 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a supply of nk bills. For example, N=3, n1=10, D1=100, n2=4, D2=50, n3=5, D3=10 means the machine has a supply of 10 bills of @100 each, 4 bills of @50 each, and 5 bills of @10 each. Call cash the requested amount of cash the machine should deliver and write a program that computes the maximum amount of cash less than or equal to cash that can be effectively delivered according to the available bill supply of the machine. Notes: @ is the symbol of the currency delivered by the machine. For instance, @ may stand for dollar, euro, pound etc. Input The program input is from standard input. Each data set in the input stands for a particular transaction and has the format: cash N n1 D1 n2 D2 ... nN DN where 0 <= cash <= 100000 is the amount of cash requested, 0 <=N <= 10 is the number of bill denominations and 0 <= nk <= 1000 is the number of available bills for the Dk denomination, 1 <= Dk <= 1000, k=1,N. White spaces can occur freely between the numbers in the input. The input data are correct. Output For each set of data the program prints the result to the standard output on a separate line as shown in the examples below. Sample Input 735 3 4 125 6 5 3 350 633 4 500 30 6 100 1 5 0 1 735 0 0 3 10 100 10 50 10 10 Sample Output 735 630 0 0 Hint The first data set designates a transaction where the amount of cash requested is @735. The machine contains 3 bill denominations: 4 bills of @125, 6 bills of @5, and 3 bills of @350. The machine can deliver the exact amount of requested cash. In the second case the bill supply of the machine does not fit the exact amount of cash requested. The maximum cash that can be delivered is @630. Notice that there can be several possibilities to combine the bills in the machine for matching the delivered cash. In the third case the machine is empty and no cash is delivered. In the fourth case the amount of cash requested is @0 and, therefore, the machine delivers no cash. */ #include <stdio.h> #include "stdlib.h" #include "string.h" #define MAX_BILL_NUMBER 100 #define MAX_REQUEST_CASH 100001 int gaiBill[MAX_BILL_NUMBER]; int gaiCash[MAX_REQUEST_CASH]; int CashMachinemain(void) { int iLoop; int iLoopCash; int iLoopDenomination; int iCashRequested; int iDenominationNum; int iTotalBillNum = 0; int iBillNum; int iDenomination; int iTempBillNum; while(EOF != scanf("%d %d",&iCashRequested,&iDenominationNum)) { iTotalBillNum = 0; memset(gaiCash,0,MAX_REQUEST_CASH*sizeof(int)); gaiCash[0]=1; for (iLoopDenomination = 0; iLoopDenomination < iDenominationNum; iLoopDenomination++) { scanf("%d %d",&iBillNum,&iDenomination); iTempBillNum = 1; for (iLoop = 0; 0 < iBillNum; iLoop++) { if(iBillNum >= iTempBillNum) { gaiBill[iTotalBillNum] = iTempBillNum*iDenomination; iBillNum -= iTempBillNum; } else { gaiBill[iTotalBillNum] = iBillNum*iDenomination; iBillNum = 0; } iTempBillNum = iTempBillNum<<1; iTotalBillNum++; } } for (iLoop = 0; iLoop < iTotalBillNum; iLoop++) { for (iLoopCash = iCashRequested; iLoopCash >= gaiBill[iLoop]; iLoopCash--) { if (0 == gaiCash[iLoopCash]) { gaiCash[iLoopCash] = gaiCash[iLoopCash - gaiBill[iLoop]]; } } } for (iLoopCash = iCashRequested; iLoopCash >= 0; iLoopCash--) { if (0 != gaiCash[iLoopCash]) { printf("%d/n",iLoopCash); break; } } } return 0; }
當全新安裝 Windows 7 SP1 後,在未安裝任何補丁,也未進行聯網的狀態下,安裝 .NET Framework 4.6/4.7 或更高的版本時, 應該會遇到錯誤提示:無法建立到信任根頒發機構的證書鏈。 解決方法 1.下載證書 地址:
在windows 2008 r2 安裝.net 4.8 ,一開始下載 .net 4.8 的web 安裝包,鏈接如下: https://download.visualstudio.microsoft.com/download/pr/2d6bb
作爲城市公共交通的核心,機車的能耗管理不僅直接關係到運營成本,更牽涉到環境保護和能源的高效、可續利用。傳統的機車監控手段在現代化需求面前已顯得力不從心,亟需構建一個能實時收集和分析運營數據的高效、智能、全面的智能化監控平臺。利用先進的可視化
主要環節 1、前端接受用戶請求,發送給後端建立任務; 2、後端接受請求後,創建任務記錄(初始狀態),將記錄發送到消息隊列; 2、消費者拿到任務後,將任務置爲running,然後向外部平臺發送請求,並向延時隊列(5分鐘)發送消息; 3、外部平
https://leetcode.cn/problems/longest-increasing-subsequence/description/ 給你一個整數數組 nums ,找到其中最長嚴格遞增子序列的長度。 子序列 是由數組派生而來的序
1. Epoch 在以太坊生態系統中,"epoch" 是一個重要的概念,特別是在以太坊 2.0 (也稱爲 Eth2 或 Serenity) 中。以太坊 2.0 引入了權益證明(Proof of Stake, PoS)共識機制,epoch 在
Yolo模型可分爲4個維度的概念 模型版本、數據集、模型變體(Variants)、動態/靜態模型。 Yolo各模型版本進展歷史 Yolov(2015年華盛頓大學的 Joseph Redmon 和 Ali Farhadi 發佈)Yolov2(
1、創建或修改 /etc/docker/daemon.json 文件 { "registry-mirrors": [ "http://hub-mirror.c.163.com", "https://d
文章很長,且持續更新,建議收藏起來,慢慢讀!瘋狂創客圈總目錄 博客園版 爲您奉上珍貴的學習資源 : 免費贈送 :《尼恩Java面試寶典》 持續更新+ 史上最全 + 面試必備 2000頁+ 面試必備 + 大廠必備 +漲薪必備 免費贈送 :《尼
gRPC入門學習之旅目錄 gRPC入門學習之旅(一) gRPC入門學習之旅(二) gRPC入門學習之旅(三) gRPC入門學習之旅(四) gRPC入門學習之旅(七) gRPC入門學習之旅(九) 3.12、依賴
HTTP The remote name could not be resolved HTTP Status:NameResolutionFailure
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Off
在基於transformer的自迴歸語言模型(LMs)中,生成令牌的成本很高,這是因爲自注意力機制需要關注所有之前的令牌,通常通過在自迴歸解碼過程中緩存所有令牌的鍵值(KV)狀態來解決這個問題。但是,加載所有先前令牌的KV狀態以計算自注意力
在開發工作中,雖然CPU,內存和硬盤都是必不可少的硬件,不過,編程中,我們常常受到困擾的往往是內存相關的bug(編程中遇到CPU和硬盤相關的bug極少)。 這是因爲我們的程序和數據雖然是存放在硬盤上的,但是運行時,CPU並不是直接從硬盤加載
前情 uni-app是我比較喜歡的跨平臺框架,它能開發小程序/H5/APP(安卓/iOS),重要的是對前端開發友好,自帶的IDE讓開發體驗非常棒,公司項目就是主推uni-app,在uniapp生態中uView是其中非常好的全平臺的第三方開源