zoukankan      html  css  js  c++  java
  • Lightoj 1231

    题目链接:

      Lightoj  1231 - Coin Change (I)

    题目描述:

      就是有n种硬币,每种硬币有两个属性(价值,数目)。问用给定的硬币组成K面值,有多少种方案?

    解题思路:

      赤果果的多重背包,简单搞一下就好了。席八!烦烦烦。今天绝对是出门刷提前没看黄历,刚开始套了一个多重背包板子,蓝而跑出来的答案并不对,改来改去就错在细节的地方。

     1 #include <cmath>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 const int mod = 100000007;
    10 const int maxn = 1010;
    11 int dp[60][maxn], a[60], c[60];
    12 
    13 int main ()
    14 {
    15     int T;
    16     scanf ("%d", &T);
    17     for (int t=1; t<=T; t++)
    18     {
    19         int n, k;
    20         scanf ("%d %d", &n, &k);
    21         memset (dp, 0, sizeof(dp));
    22         dp[0][0] = 1;
    23 
    24         for (int i=1; i<=n; i++)
    25             scanf ("%d", &a[i]);
    26         for (int i=1; i<=n; i++)
    27             scanf ("%d", &c[i]);
    28 
    29         for (int i=1; i<=n; i++)
    30             for (int j=0; j<=c[i]; j++)
    31                 for (int x=k; x>=a[i]*j; x--)
    32             {
    33                 dp[i][x] = (dp[i][x] + dp[i-1][x-a[i]*j]) % mod;
    34             }
    35 
    36         printf ("Case %d: %d
    ", t, dp[n][k]);
    37     }
    38     return 0;
    39 }
    本文为博主原创文章,未经博主允许不得转载。
  • 相关阅读:
    数据结构64:冒泡排序算法(起泡排序)
    数据结构63:希尔排序算法(缩小增量排序)
    Python3 内置函数
    Python3 解压序列
    Python3 装饰器
    Python3 函数
    Python3 迭代器和生成器
    Python3 函数式编程自带函数
    Python3 函数式编程
    Python3 匿名函数
  • 原文地址:https://www.cnblogs.com/alihenaixiao/p/4942820.html
Copyright © 2011-2022 走看看