HDU 3591 The trouble of Xiaoqian(多重背包+完全背包)

本文介绍了一道关于使用最少数量的硬币完成购物支付的问题。主人公小倩希望通过精确计算使用最少的硬币来购买所需商品。面对不同面额的硬币及有限的携带数量,如何在不超过一定数额的情况下完成支付成为挑战。文章提供了使用多重背包算法解决此问题的代码实现。

The trouble of Xiaoqian

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2451    Accepted Submission(s): 867


Problem Description
In the country of ALPC , Xiaoqian is a very famous mathematician. She is immersed in calculate, and she want to use the minimum number of coins in every shopping. (The numbers of the shopping include the coins she gave the store and the store backed to her.)
And now , Xiaoqian wants to buy T (1 ≤ T ≤ 10,000) cents of supplies. The currency system has N (1 ≤ N ≤ 100) different coins, with values V1, V2, ..., VN (1 ≤ Vi ≤ 120). Xiaoqian is carrying C1 coins of value V1, C2 coins of value V2, ...., and CN coins of value VN (0 ≤ Ci ≤ 10,000). The shopkeeper has an unlimited supply of all the coins, and always makes change in the most efficient manner .But Xiaoqian is a low-pitched girl , she wouldn’t like giving out more than 20000 once.
 

Input
There are several test cases in the input.
Line 1: Two space-separated integers: N and T. 
Line 2: N space-separated integers, respectively V1, V2, ..., VN coins (V1, ...VN) 
Line 3: N space-separated integers, respectively C1, C2, ..., CN
The end of the input is a double 0.
 

Output
Output one line for each test case like this ”Case X: Y” : X presents the Xth test case and Y presents the minimum number of coins . If it is impossible to pay and receive exact change, output -1.
 

Sample Input
      
3 70 5 25 50 5 2 1 0 0
 

Sample Output
      
Case 1: 3
应用多重背包求解dp[T]-dp[20000],即xioaqian付T~20000分别需要的硬币数,然后用完全背包求解dp2[1]-dp2[20000],
dp2[j]为店主找j元钱所需要的硬币数,因此只需找出最小的dp[j]+dp2[j-T]即可。
注意:初始化时将dp设为无穷大,付0元需要0个硬币,所以dp[0]=0,dp2[0]=0;这样最后若无法通过付钱找钱得到T,则dp[j]+dp2[j-T]为无穷大。
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
int dp[20003],INF=1e9,dp2[20002];
using namespace std;
int main()
{
    int N, T, ca = 1;
    while (scanf_s("%d%d", &N, &T) != EOF)
    {
        if (!(N + T))break;
        int v[102], c[102];
        for (int i = 1; i <= N; i++)
            scanf_s("%d", &v[i]);
        for (int i = 1; i <= N; i++)
            scanf_s("%d", &c[i]);
        for (int i = 0; i <= 20000; i++)
            dp[i] = INF, dp2[i] = INF;
        dp[0] = 0;
        for (int i = 1; i <= N; i++)
        {
            int k = 1, M = c[i];
            while (k < M)
            {
                for (int j = 20000; j >=k*v[i]; j--)
                {
                    dp[j] = min(dp[j], dp[j - k * v[i]] + k);
                }
                M = M - k; k = 2 * k;
            }
            for (int j = 20000; j >= M * v[i]; j--)
            {
                dp[j] = min(dp[j], dp[j - M * v[i]] + M);
            }
        }
        dp2[0] = 0;
        for (int i = 1; i <= N; i++)
        {
            for (int j = v[i]; j <= 20000; j++)
            {
                dp2[j] = min(dp2[j], dp2[j - v[i]] + 1);
            }
        }
        int mi = INF;
        for (int i = T; i <= 20000; i++)
        {
            int t = i - T;
            if (dp[i] + dp2[t] < mi) mi = dp[i] + dp2[t];
        }
        if (mi == INF) printf("Case %d: -1\n", ca);
        else printf("Case %d: %d\n",ca, mi);
        ca++;
    }
    return 0;
}

内容概要:本文系统介绍了基于Matlab构建的简化单粒子(SPM)电化学模型及其参数化方法,聚焦于锂离子电池的降阶电化学模型P2D的简化实现,涵盖模型建立、参数辨识、测试数据提供及仿真验证全流程。资源核心在于深入剖析电化学模型的关键参数提取与优化过程,帮助科研人员理解电池内部反应机理与数学建模范式,支持后续的模型扩展与工程应用。文档不仅提供了完整的SPM模型代码与参数拟合工具,还整合了丰富的科研辅助资源,包括智能优化算法、机器学习、电力系统管理、路径规划、信号处理等多个领域的Matlab/Simulink仿真案例与Python实现方案,极大拓展了该模型在电池健康状态(SOH)估计、寿命预测、充放电控制策略等方向的应用潜力。; 适合人群:具备一定Matlab编程能力,从事新能源技术、电化学建模、电池管理系统(BMS)、储能控制、自动化仿真等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①开展锂离子电池电化学模型的建模与参数辨识研究;②实现P2D与SPM降阶模型的仿真与实验验证;③结合实测数据进行模型参数拟合与精度优化;④拓展应用于电池老化分析、SOH估算、充放电策略设计及储能系统动态响应研究。; 阅读建议:建议读者按照文档结构循序渐进学习,重点研读SPM模型构建与参数辨识章节,结合所提供的测试数据与代码进行动手实践,并积极借鉴附带的智能算法与机器学习模块以提升模型鲁棒性与预测精度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值