先上题目:

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. Error-Java-IJ:Imported project refers to unknown jdks JavaSE-1.7

    ylbtech-Error-Java-IJ:Imported project refers to unknown jdks JavaSE-1.7 Import from EclipseImported ...

  2. .NET页面事件执行顺序

    摘自:http://www.cnblogs.com/kenkofox/archive/2011/03/18/1987998.html和http://blog.csdn.net/yiruoyun/art ...

  3. python 内存泄露的诊断

    对于一个用 python 实现的,长期运行的后台服务进程来说,如果内存持续增长,那么很可能是有了"内存泄露" 一.内存泄露的原因 对于 python 这种支持垃圾回收的语言来说,怎 ...

  4. 跟渣渣辉玩ffms

    [SQL] /* Navicat MySQL Data Transfer Source Server : root Source Server Version : 50717 Source Host ...

  5. 玩游戏(dfs)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2566 #include <stdio.h ...

  6. bzoj1588: [HNOI2002]营业额统计(权值线段树)

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 16863  Solved: 6789[Submit][Sta ...

  7. 后台传list,前台接受

    @RequestMapping("/page1") public ModelAndView editSharing(Integer id) { ModelAndView mav=n ...

  8. MSSQL:删除系统作业计划

    use [msdb]declare @job_name varchar(100)set @job_name = N'EveryDayBackup.Subplan_1'--注:jobName为维护计划对 ...

  9. django的admin后台管理如何更改为中文

    新建Django的admin后端控制为英文显示,为了可以使其显示中文,可以将 setting.py配置文件修改 # LANGUAGE_CODE = 'en-us' # # # # # TIME_ZON ...

  10. Spring的AOP机制---- 切入点表达式---- 切入点表达式

    3333钱钱钱钱钱钱钱钱钱钱钱钱钱钱钱