LightOJ 1231 Coin Change (I) (背包计数模板题)

DeepSeek在教育平台考试作弊检测中的作用规划方案.pptx 立即下载
1231 - Coin Change (I)
Time Limit: 1 second(s)Memory Limit: 32 MB

In a strange shop there are n types of coins of valueA1, A2 ... An.C1, C2,... Cn denote the number of coins of valueA1, A2... An respectively. You have to find the number of ways you canmakeK using the coins.

For example, suppose there are three coins 1, 2, 5 and wecan use coin 1 at most 3 times, coin 2 at most 2 times and coin 5 at most 1time. Then ifK = 5 the possible ways are:

1112

122

5

So, 5 can be made in 3 ways.

Input

Input starts with an integer T (≤ 100),denoting the number of test cases.

Each case starts with a line containing two integersn (1≤ n ≤ 50) andK (1 ≤ K ≤ 1000). The nextline contains2n integers, denotingA1, A2 ...An, C1, C2... Cn (1 ≤ Ai≤ 100, 1 ≤ Ci ≤ 20). AllAiwill be distinct.

Output

For each case, print the case number and the number of waysKcan be made. Result can be large, so, print the result modulo100000007.

Sample Input

Output for Sample Input

2

3 5

1 2 5 3 2 1

4 20

1 2 3 4 8 4 2 1

Case 1: 3

Case 2: 9

 

题目链接:http://lightoj.com/volume_showproblem.php?problem=1231


题目大意:n种面值为a[i]的硬币,每种对应c[i]个,求能组成金额K的方案数。


解题思路:背包计数 ,dp[i][j]表示前 i 种硬币能组成面值为 j 的方案个数。每个a[i]可用0-c[i]次。递推方程为:当满足条件j-k*a[i]>=0时,dp[i][j]=dp[i-1][j]+dp[i-1][j-k*a[i]]。


代码如下:

#include <cstdio>
#include <cstring>
#define mod 100000007;
int a[52],c[52];
int dp[52][1005];
int main()
{
    int t,cnt=0,n,v,i,j,k;
    scanf("%d",&t);
    while(t--)
    {
		memset(dp,0,sizeof(dp));
        scanf("%d%d",&n,&v);
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(i=1;i<=n;i++)
            scanf("%d",&c[i]);
		dp[0][0]=1;
        for(i=1;i<=n;i++)
            for(j=0;j<=v;j++)
                for(k=0;k<=c[i];k++)
                {
                    if(j-k*a[i]>=0)
                        dp[i][j]=(dp[i][j]+dp[i-1][j-k*a[i]])%mod;
                }
		printf("Case %d: %d\n",++cnt,dp[n][v]);
    }
    return 0;
}


从零开始:IBM V3700控制器更换与机器代码升级全流程指南 本文详细介绍了IBM V3700存储系统控制器更换与机器代码升级的全流程指南。从前期准备、硬件更换到版本同步,逐步解析如何应对503错误等常见问题,确保系统稳定运行。通过实战案例和优化建议,帮助工程师高效完成维护任务,提升存储系统可用性。 阅读详情

相关推荐

广义平均(Generalized Mean, GeM)

本位介绍了广义平均操作的定义和简要推导,帮助大家理解其含义。

qq_45802280的博客 4553

背包问题 模板详解!

一、01背包 题目描述: 有 N 件物品和一个容量是 V 的背包。每件物品只能使用一次。第 i 件物品的体积是 vi,价值是 wi 。 求解将哪些物品装入背包,可使这些物品的总体积不超过背包容量,且总价值最大。 输出最大价值。 每件物品只能 不选0,或者选一次1,所以叫做01背包。(好生动 QwQ) —————朴素做法: 1、状态表示:f[i][j]表示从前i个物品中选,总体积不超过j的最大价值; 2、属性: 最大值; 3、状态转移: 用“最后一步”来划分:当前物品“选不选”: 不选当前物品,那么当.

Mr_dimple的博客 2079

常见消息队列:ActiveMQ、RabbitMQ、RocketMQ、Kafka的区别总结

常见消息队列:ActiveMQ、RabbitMQ、RocketMQ、Kafka的区别。

qq_30713721的博客 3481

lightoj1231--Coin Change (I)(简单dp,背包计数)

Description In a strange shop there are n types of coins of value A1, A2 ... An. C1, C2, ... Cn denote the number of coins of value A1, A2 ... An respectively. You have to find the number of ways

shengtao96的专栏 595

drm 之modes

#define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <time.h&...

u012794472的专栏 3730

NetApp 7-mode初始化详解(原AGGR重建)及注意事项

没想到有生之年还能再写个7-mode的文章,上次接触可能已将近十年,本次恰巧碰到这个机会,边学习边整理,整整一天时间,碰到了不少坑,作为记录。

RaySun的技术Blog 2757

LightOJ 1231 Coin Change (I) (线性dp 背包计数)

1231 - Coin Change (I) PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB In a strange shop there are n types of coins of va

Tc的专栏 1419

置顶必读(1) |《滚雪球学 Spring Boot 4.x》专栏目录导航篇(持续更新中)!

🏆 本文收录于 《滚雪球学 Spring Boot 4.x》 专栏。 本专栏面向 有一点 Java 基础,但没有系统学过 Spring Boot 的读者,采用“滚雪球式学习法”:先跑通、再理解、再重构、再上线,最终带你从第一个 Hello API 一路完成一个可部署、可监控、可扩展的后端项目。

**My Coding Family** 8万+

LightOj 1231 Coin Change (I)(部分背包)

Coin Change (I) Description In a strange shop there are n types of coins of value A1, A2 ... An. C1, C2, ... Cn denote the number of coins of value A1, A2 ... An respectively. You have to fi

piaocoder 465

C#上位机与西门子PLC全链路通信实战教程:数据采集+SQL存储+数据库报表查询+报警历史完整实现

在工业自动化领域,西门子PLC(S7-200Smart/1200/1500)凭借稳定的性能、强大的功能、完善的生态,稳居工业控制器的主流地位;而凭借开发效率高、界面美观、兼容性强、数据库操作便捷的优势,成为工业上位机开发的首选编程语言。二者的组合,是目前制造业、自动化产线、智能仓储、暖通自控等场景的绝对主流方案,也是工业上位机工程师必须吃透的核心技术栈。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1873

MNE系列教程1——MNE的安装与基本绘图

MNE系列教程1——MNE的安装与基本绘图

m0_51339444的博客 2661

Codeforces Round #338 (Div. 2) B. Longtail Hedgehog

B. Longtail Hedgehog time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output This Christmas Santa gave Masha a magic picture and a pencil. The pic

ysCover 3万+

YOLO26科研升级:OREPA在线重参数化,让模型精度在训练中持续跃升

在目录下,新建AddModules文件夹,将orepa.py放入其中。

LXY_LOVE36的博客 101

P1990 覆盖墙壁

你有一个长为N宽为2的墙壁,给你两种砖头:一个长2宽1,另一个是L型覆盖3个单元的砖头。如下图: 0  0 0  00 砖头可以旋转,两种砖头可以无限制提供。你的任务是计算用这两种来覆盖N*2的墙壁的覆盖方法。例如一个2*3的墙可以有5种覆盖方法,如下: 012 002 011 001 011 012 112 022 011 001 注意可以使用两种砖头混合起来覆盖,如2*4的墙可以这

ysCover 1475

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Codeforces 518D Ilya and Escalator

D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ilya got tired of sports programming,

ysCover 1026

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

LightOJ 1004 Monkey Banana Problem (DP 数字三角形)

1004 - Monkey Banana Problem PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are in the world of mathematics to solve the gre

ysCover 919

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

LightOJ 1047 Neighbor House (DP 数字三角形变形)

1047 - Neighbor House PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: 32 MB The people of Mohammadpur have decided to paint each ofth

ysCover 841

noj 1860 保研(01背包 概率dp)

C. 保研 时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte 总提交 : 171            测试通过 : 40  题目描述     对于一些名校而言,保研不仅可以由学校推免,也可以由学生自己向希望保研的学校提出申请,这个过程有点类似于外国学生向学校提交简历等待Offer的过程。但是,投递

ysCover 820

poj 1088 滑雪(线性DP)

滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 81553   Accepted: 30437 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升

ysCover 750

hdu 1231 最大连续子序列(DP)

最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 21166    Accepted Submission(s): 9387 Problem Description 给定K个整数的序列{ N1, N2

ysCover 730

poj 2250 Compromise(裸LCS DP)

Compromise Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6766   Accepted: 3023   Special Judge Description In a few months the European Currency Union

ysCover 702

P1616 疯狂的采药

题目描述 Description LiYuxiang是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师。为此,他想拜附近最有威望的医师为师。医师为了判断他的资质,给他出了一个难题。医师把他带到一个到处都是草药的山洞里对他说:“孩子,这个山洞里有一些不同种类的草药,采每一种都需要一些时间,每一种也有它自身的价值。我会给你一段时间,在这段时间里,你可以采到一些草药。如果你是一个聪明的孩

ysCover 687

poj 3624 Charm Bracelet

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25370   Accepted: 11418 Description Bessie has gone to the mall's jewelry store and spies a

ysCover 673

poj 1836 Alignment (DP LIS)

Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13839   Accepted: 4478 Description In the army, a platoon is composed by n soldiers. During the m

ysCover 603

hdu 1087 Super Jumping! Jumping! Jumping!(DP)

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25057    Accepted Submission(s): 11073 Problem De

ysCover 588

hdu 1506 Largest Rectangle in a Histogram (DP)

Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12947    Accepted Submission(s): 3653 Problem Des

ysCover 559
上一篇: poj 2250 Compromise(裸LCS DP)
下一篇: hdu 3127 WHUgirls(完全背包)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址