Uva--10626(动规,记忆化搜索)

本文探讨了在特定条件下购买可乐并获得最少硬币找零的问题,通过动态规划算法解决,具体介绍了输入输出格式及样例。

2014-08-21 10:50:10

Problem D
Buying Coke 
Input: Standard Input

Output: Standard Output

Time Limit: 2 Seconds

I often buy Coca-Cola from the vending machine at work. Usually I buy several cokes at once, since my working mates also likes coke. A coke in the vending machine costs 8 Swedish crowns, and the machine accept crowns with the values 15 and 10. As soon as I press the coke button (after having inserted sufficient amount of money), I receive a coke followed by the exchange (if any). The exchange is always given in as few coins as possible (this is uniquely determined by the coin set used). This procedure is repeated until I've bought all the cokes I want. Note that I can pick up the coin exchange and use those coins when buying further cokes.

Now, what is the least number of coins I must insert, given the number of cokes I want to buy and the number of coins I have of each value? Please help me solve this problem while I create some harder problems for you. You may assume that the machine won't run out of coins and that I always have enough coins to buy all the cokes I want.

Input

The first line in the input contains the number of test cases (at most 50). Each case is then given on a line by itself. A test case consists of four integers: C (the number of cokes I want to buy), n1n5n10 (the number of coins of value 15 and 10, respectively). The input limits are 1 <= C <= 1500 <= n1 <= 5000 <= n5 <= 100 and 0 <= n10 <= 50.

Output

For each test case, output a line containing a single integer: the minimum number of coins needed to insert into the vending machine.

Sample Input                               Output for Sample Input

3 
2 2 1 1 
2 1 4 1 
20 200 3 0 
 
        
5 
3 
148 

  

 

 

思路:纯记忆话搜索,要注意的是找零有3种:(1)10元找 两张1元;(2)两张5元找 两张1元;(3)一张10元3张1元找 一张5元。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 using namespace std;
 5 const long long INF = 1e17;
 6 typedef long long ll;
 7 
 8 int Case;
 9 int n[3];
10 int v[3] = {1,5,10};
11 ll dp[705][155][55];
12 int c;
13 
14 ll Solve(int n,int v0,int v1,int v2){
15     if(n == 0)
16         return 0;
17     if(dp[v0][v1][v2] != -1)
18         return dp[v0][v1][v2];
19     ll tmin = INF;
20     if(v2){
21         tmin = min(tmin,Solve(n - 1,v0 + 2,v1,v2 - 1) + 1);
22     }
23     if(v1 && v0 >= 3){
24         tmin = min(tmin,Solve(n - 1,v0 - 3,v1 - 1,v2) + 4);
25     }
26     if(v1 >= 2){
27         tmin = min(tmin,Solve(n - 1,v0 + 2,v1 - 2,v2) + 2);
28     }
29     if(v0 >= 8){
30         tmin = min(tmin,Solve(n - 1,v0 - 8,v1,v2) + 8);
31     }
32     if(v0 >= 3 && v2){
33         tmin = min(tmin,Solve(n - 1,v0 - 3,v1 + 1,v2 - 1) + 4);
34     }
35     return dp[v0][v1][v2] = tmin;
36 }
37 
38 int main(){
39     scanf("%d",&Case);
40     while(Case--){
41         memset(dp,-1,sizeof(dp));
42         scanf("%d%d%d%d",&c,&v[0],&v[1],&v[2]);
43         printf("%lld\n",Solve(c,v[0],v[1],v[2]));
44     }
45     return 0;
46 }

 

转载于:https://www.cnblogs.com/naturepengchen/articles/3926656.html

先看效果: https://renmaiwang.cn/s/jkhfz Hue系列产品将具备高度的个性化定制能力,并且借助内置红、蓝、绿三原色LED的灯泡,能够混合生成1600万种不同色彩的灯光。 整个操作流程完全由安装于iPhone上的应用程序进行管理。 这一创新举措为智能照明控制领域带来了新的启示,国内相关领域的从业者也积极投身于相关研究。 鉴于Hue产品采用WiFi无线连接方式,而国内WiFi网络尚未全面覆盖,本研究选择应用更为普及的蓝牙技术,通过手机蓝牙与单片机进行数据交互,进而产生可调节占空比的PWM信号,以此来控制LED驱电路,实现LED的调光功能以及DIY调色方案。 本文重点阐述了一种基于手机蓝牙通信的LED灯设计方案,该方案受到飞利浦Hue智能灯泡的启发,但考虑到国内WiFi网络的覆盖限制,故而选用更为通用的蓝牙技术。 以下为相关技术细节的详尽介绍:1. **智能照明控制系统**:智能照明控制系统允许用户借助手机应用程序实现远程控制照明设备,提供个性化的调光及色彩调整功能。 飞利浦Hue作为行业领先者,通过红、蓝、绿三原色LED的混合,能够呈现1600万种颜色,实现了全面的定制化体验。 2. **蓝牙通信技术**:蓝牙技术是一种低成本、短距离的无线传输方案,工作于2.4GHz ISM频段,具备即插即用和强抗干扰能力。 蓝牙协议栈由硬件层和软件层构成,提供通用访问Profile、服务发现应用Profile以及串口Profiles等丰富功能,确保不同设备间的良好互操作性。 3. **脉冲宽度调制调光**:脉冲宽度调制(PWM)是一种高效能的调光方式,通过调节脉冲宽度来控制LED的亮度。 当PWM频率超过200Hz时,人眼无法察觉明显的闪烁现象。 占空比指的...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值