码迷,mamicode.com
首页 > 其他好文 > 详细

icpc2018焦作Transport Ship(背包思想)

时间:2018-09-16 16:06:47      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:anti   define   sign   while   ==   etc   names   efi   scan   

传送门

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\n",dp[qdata]);
        }
    }
    return 0;
}

 

icpc2018焦作Transport Ship(背包思想)

标签:anti   define   sign   while   ==   etc   names   efi   scan   

原文地址:https://www.cnblogs.com/WindFreedom/p/9655712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!