zoukankan      html  css  js  c++  java
  • ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship

    There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry the weight of V[i]V[i] and the number of the i^{th}ith kind of ship is 2^{C[i]} - 12C[i]1. How many different schemes there are if you want to use these ships to transport cargo with a total weight of SS?

    It is required that each ship must be full-filled. Two schemes are considered to be the same if they use the same kinds of ships and the same number for each kind.

    Input

    The first line contains an integer T(1 le T le 20)T(1T20), which is the number of test cases.

    For each test case:

    The first line contains two integers: N(1 le N le 20), Q(1 le Q le 10000)N(1N20),Q(1Q10000), representing the number of kinds of ships and the number of queries.

    For the next NN lines, each line contains two integers: V[i](1 le V[i] le 20), C[i](1 le C[i] le 20)V[i](1V[i]20),C[i](1C[i]20), representing the weight the i^{th}ith kind of ship can carry, and the number of the i^{th}ith kind of ship is 2^{C[i]} - 12C[i]1.

    For the next QQ lines, each line contains a single integer: S(1 le S le 10000)S(1S10000), representing the queried weight.

    Output

    For each query, output one line containing a single integer which represents the number of schemes for arranging ships. Since the answer may be very large, output the answer modulo 10000000071000000007.

    样例输入

    1
    1 2
    2 1
    1
    2

    样例输出

    0
    1

    题目来源

    ACM-ICPC 2018 焦作赛区网络预赛

    题解:二进制求和+DP

    参考代码:

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<math.h>
     4 #include<string.h>
     5 #include<string>
     6 #include<algorithm>
     7 #include<bitset>
     8 #define INF 0x3f3f3f3f
     9 #define clr(x, y) memset(x, y, sizeof(x))
    10 #define mod 1000000007
    11 using namespace std;
    12 typedef long long LL;
    13 const int maxn=25;
    14 const int maxm=10010;
    15 int v[maxn],c[maxn];
    16 LL dp[maxm];
    17 
    18 int main()
    19 {
    20     int t;
    21     scanf("%d", &t);
    22     while(t--)
    23     {
    24         int n, q;
    25         scanf("%d%d", &n, &q);
    26         memset(dp, 0, sizeof(dp));
    27         dp[0] = 1;
    28         for(int i = 1; i <= n; i++)
    29         {
    30             scanf("%d%d", &v[i], &c[i]);
    31             LL cur = 1;
    32             for(int j = 1; j <= c[i]; j++)
    33             {
    34                 for(int k = 10000; k >= cur * v[i]; k--)
    35                     dp[k] = (dp[k] + dp[k - cur * v[i]]) % mod;
    36                 cur<<=1;
    37             }
    38         }
    39         for(int i = 1; i <= q; i++)
    40         {
    41             int s;
    42             scanf("%d", &s);
    43             printf("%lld
    ", dp[s]);
    44         }
    45     }
    46     return 0;
    47 }
    View Code

      

  • 相关阅读:
    vue-cli构建的项目手动添加eslint配置
    给通过canvas生成的二维码添加logo
    webpack打包时候去掉console.log配置
    gist.github.com 被墙无法访问解决办法
    axios.js 在测试机ios7.1的iphone4中不能发送http请求解决方案
    linux 系统的7个运行级别
    今天遇到了不能创建mysql函数
    今天测试大商创,遇到了 upstream sent too big header while reading response header from upstream
    mysql5.7 datetime 默认值为‘0000-00-00 00:00:00'值无法创建问题解决
    IE浏览器中判断IE版本
  • 原文地址:https://www.cnblogs.com/csushl/p/9651985.html
Copyright © 2011-2022 走看看