zoukankan      html  css  js  c++  java
  • lightoj1232_完全背包

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

    题意: 给出n种硬币的币值,每种硬币最多有k个,问用这n种硬币组成k的方案数

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cstdio>
     6 #include <vector>
     7 #include <ctime>
     8 #include <queue>
     9 #include <list>
    10 #include <set>
    11 #include <map>
    12 using namespace std;
    13 #define INF 0x3f3f3f3f
    14 #define mod 100000007
    15 typedef long long LL;
    16 
    17 int val[105], num[105], dp[10005];
    18 int main()
    19 {
    20     int t, n, k;
    21     scanf("%d", &t);
    22     for(int ca = 1; ca <= t; ca++)
    23     {
    24         scanf("%d %d", &n, &k);
    25         for(int i = 1; i <= n; i++)
    26             scanf("%d", &val[i]);
    27         memset(dp, 0, sizeof(dp));
    28         dp[0] = 1;
    29         for(int i = 1; i <= n; i++)
    30         {
    31             for(int j = val[i]; j <= k; j++)
    32             {
    33                 dp[j] = (dp[j] + dp[j - val[i]]) % mod;
    34             }
    35         }
    36         printf("Case %d: %d
    ", ca, dp[k]);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    [恢]hdu 2391
    [恢]hdu 2352
    [恢]hdu 2393
    [恢]hdu 1868
    [恢]hdu 1279
    [恢]hdu 2086
    [恢]hdu 1405
    [恢]hdu 2088
    [恢]hdu 2106
    [恢]hdu 2537
  • 原文地址:https://www.cnblogs.com/luomi/p/5925015.html
Copyright © 2011-2022 走看看