Transport Ship - 计蒜客

ps:看出是多重背包了,但不会计算方案数。

const int mod = 1000000007;
const int N = 10005;

int n, q, tot;
int dp[N], v[N];

inline void upd(int &x, int y) {
    (x < y) && (x = y);
}

int main()
{
    BEGIN() {
        mem(dp, 0);
        dp[0] = 1;

        sc(n), sc(q);
        tot = 0;
        Rep(i, 1, n) {
            int x, y;
            sc(x), sc(y);
            Rep(j, 1, y) {
                v[++tot] = (1 << (j - 1)) * x;
            }
        }

        Rep(i, 1, tot) {
            for (int j = 10000; j >= v[i]; --j) {
                dp[j] += dp[j - v[i]];
                dp[j] %= mod;
            }
        }

        while(q--) {
            int x;
            sc(x);
            pr(dp[x]);
        }
    }
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-12-06
  • 2021-04-29
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-18
  • 2021-07-14
  • 2021-10-25
  • 2021-11-27
  • 2021-12-22
  • 2021-09-29
  • 2021-09-20
相关资源
相似解决方案