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;
}
原文地址:https://www.cnblogs.com/zgglj-com/p/9678336.html