先上题目:

1232 - Coin Change (II)
Time Limit: 1 second(s) Memory Limit: 32 MB

In a strange shop there are n types of coins of value A1, A2 ... An. You have to find the number of ways you can make K using the coins. You can use any coin at most K times.

For example, suppose there are three coins 1, 2, 5. Then if K = 5 the possible ways are:

11111

1112

122

5

So, 5 can be made in 4 ways.

Input

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

Each case starts with a line containing two integers n (1 ≤ n ≤ 100) and K (1 ≤ K ≤ 10000). The next line contains n integers, denoting A1, A2 ... An (1 ≤ Ai ≤ 500). All Ai will be distinct.

Output

For each case, print the case number and the number of ways K can be made. Result can be large, so, print the result modulo 100000007.

Sample Input

Output for Sample Input

2

3 5

1 2 5

4 20

1 2 3 4

Case 1: 4

Case 2: 108

  题意:有n种硬币,各有其价值,给你一个数k,问你有多少种方法可以用这n种硬币凑出k,其中每种硬币最多可以用k个。

   根据题意分析,可以发现这是一条完全背包。

  分析:对于每一种的硬币可以用k个,如果硬币的价值最小(等于1),最多可以用k个,那就说明对于每一个物品在这里都是刚好可以放满体积为k的背包或者有剩余(或者说溢出,总之就是数量是过量的意思),这样我们就可以将它看成是一个完全背包了。

  状态转移方程:dp[i][j]=(dp[i][j]%MOD+dp[i-1][j-l*a[i]]%MOD)%MOD

  优化以后就是dp[i]=(dp[i]%MOD+dp[i-[i]]%MOD)%MOD  (注意这里的i和上面的i意思不一样,上面的i代表第i中硬币,这里的i代表背包体积)。

上代码:

 #include <cstdio>
#include <cstring>
#define MAX 10002
#define MOD 100000007
using namespace std; int a[];
int dp[MAX]; int main()
{
int t,n,k;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
for(int cal=;cal<=t;cal++){
memset(dp,,sizeof(dp));
scanf("%d %d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
dp[]=;
for(int i=;i<=n;i++){
for(int j=a[i];j<=k;j++){
dp[j]=(dp[j]+dp[j-a[i]])%MOD;
}
}
printf("Case %d: %d\n",cal,dp[k]);
}
return ;
}

1232

LightOJ - 1232 - Coin Change (II)的更多相关文章

  1. Coin Change (II)(完全背包)

                                                               Coin Change (II) Time Limit: 1000MS   Mem ...

  2. Lightoj 1231 - Coin Change (I) (裸裸的多重背包)

    题目链接: Lightoj  1231 - Coin Change (I) 题目描述: 就是有n种硬币,每种硬币有两个属性(价值,数目).问用给定的硬币组成K面值,有多少种方案? 解题思路: 赤果果的 ...

  3. LightOJ - 1231 - Coin Change (I)

    先上题目: 1231 - Coin Change (I)   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit:  ...

  4. LightOJ 1235 - Coin Change (IV) (折半枚举)

    题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1235 题目描述: 给出n个硬币,每种硬币最多使用两次,问能否组成K面值? 解 ...

  5. Lightoj 1235 - Coin Change (IV) 【二分】

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1235 题意: 有N个硬币(N<=18).问是否能在每一个硬币使用不超过两 ...

  6. C - Coin Change (III)(多重背包 二进制优化)

    C - Coin Change (III) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  7. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  8. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. HDU 2069 Coin Change

    Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

随机推荐

  1. everything的使用

    https://www.voidtools.com/support/everything/searching/ 打开多个everything进程 https://www.voidtools.com/s ...

  2. 无损压缩算法历史——熵编码是最早出现的,后来才有Lzx这些压缩算法

    Lossless   Entropy type Unary Arithmetic Asymmetric Numeral Systems Golomb Huffman  Adaptive Canonic ...

  3. Codeforces--629A--Far Relative’s Birthday Cake(暴力模拟)

    Far Relative's Birthday Cake Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d &a ...

  4. 【POJ 2676】 Sudoku

    [题目链接] http://poj.org/problem?id=2676 [算法] 深度优先搜索 [代码] #include <algorithm> #include <bitse ...

  5. 基于Spark的网站日志分析

    本文只展示核心代码,完整代码见文末链接. Web Log Analysis 提取需要的log信息,包括time, traffic, ip, web address 进一步解析第一步获得的log信息,如 ...

  6. 0503 php中for与foreach的区别

    结论: foreach:只能用于数组和对象,如果是非索引数组,只可以用foreach. for:如果是索引数组,可以用for遍历. foreach循环结构是按照数组内部的指针去循环的,当 foreac ...

  7. css 浮动问题详解

    浮动(float),一个我们即爱又恨的属性.爱,因为通过浮动,我们能很方便地布局: 恨,浮动之后遗留下来太多的问题需要解决,特别是IE6-7(以下无特殊说明均指 windows 平台的 IE浏览器). ...

  8. JavaScript中的+= 是什么?

    +=表示相加并赋值,“i+=5”与“i=i+5”是等效的. 类似的运算符还有-=,*=,/=. i-=5等价于i=i-5; i*=5等价于i=i*5: i/=5等价于i=i/5.

  9. Oracle 数据导入导出(imp/exp)

    环境:windows下,oracle11g 1.启动oracle服务 net start OracleDBConsoleorclnet start OracleOraDb11g_home1TNSLis ...

  10. 20小时掌握网站开发(免费精品htmlcss视频教程)

    自己最近研发了一套新的htmlcss教程,并进行了授课实施,视频教程百度云下载链接如下: 视频及案例源码下载地址 本套教程视频需要安装屏幕录像专家软件才能观看,屏幕录像专家下载地址如下: 屏幕录像专家 ...