icpc2018焦作Transport Ship(背包思想)

传送门

ac代码:

#include<bits/stdc++.h>
#define per(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
//#define int long long
const ll inf =2333333333333333LL;
const double eps=1e-8;
int read(){
    char ch=getchar();
    int res=0,f=0;
    while(ch<'0' || ch>'9'){f=(ch=='-'?-1:1);ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+(ch-'0');ch=getchar();}
    return res*f;
}
// ------------------------head
#define mod 1000000007
const int siz=10005;
int T,n,q,v,c,qdata;
ll dp[siz];

signed main()
{
   scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&q);
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        for(int i=1;i<=n;i++){
            scanf("%d%d",&v,&c);
            int cnt=1;
            for(int j=0;j<c;j++){
                for(int k=10000;k>=cnt*v;k--)dp[k]=(dp[k]+dp[k-cnt*v])%mod;
                cnt*=2;
            }
        }
        per(i,1,q){
            scanf("%d",&qdata);
            printf("%lld
",dp[qdata]);
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/WindFreedom/p/9655712.html