九校联考DAY1T1(dp,完全背包)

题目描述

铜企鹅是企鹅餐馆的老板,他正在计划如何使得自己本年度收益增加。
共有 n n 种食材,一份食材 i 需要花 ti t i 小时不间断地进行播种,施肥, 直至收获。当然,一份食材 i i 是可以直接卖掉得到 wi 块钱的。
招牌菜共有 m m 种,一份招牌菜 i i 需要消耗一定的食材,花 Ti 小时不间断地来烹饪,叫卖,并最终卖出得到 Wi W i 块钱。
整个季度换算下来一共有 Tmax T m a x 小时可供你使用,铜企鹅需要在这期间赚到最多的钱,这样他才有足够多的钱来 steam 剁手,或者氪金手游。

输入格式

第一行一个整数 T T ,表示数据组数。令 i 表示为当前数据内行数。
第一行三个整数 n n , m, Tmax T m a x ,含义如题所示。
第二行至第 n+1 n + 1 行,每行两个整数 ti1 t i − 1 , wi1 w i − 1 ,含义如题所示。
n+2 n + 2 行至第 n+m+1 n + m + 1 行,每行两个整数 Tin1,Win2 T i − n − 1 , W i − n − 2 ,含义如题所示。
n+m+2 n + m + 2 行至第 n+2m+1 n + 2 m + 1 行,每行 n n 个整数,第 j j 个数 dj 表示招牌菜 inm1 i − n − m − 1 需要 dj d j 个食材 j j

输出格式

对于每组数据,输出一行一个整数,表示你所能赚到的最多的钱。

样例数据

input
3
1 1 48
2 2000
9 21864
5
4 4 46
17 52
4 36
5 43
16 62
9 31659
1 20431
4 623
1 11961
4 5 3 5
5 4 3 4
3 3 3 3
4 4 5 5
10 0 48
10 41
18 48
2 14
22 65
12 77
7 48
4 85
2 61
24 85
8 34
output
53728
410
1464

数据规模与约定


对于 100% 的数据,保证 0 < ti,Ti Tmax T m a x ≤ 5000, 0 ≤ wi,Wi w i , W i 109 10 9 , 每份招牌菜使用的食材的个数总数不超过 105 10 5
时间限制: 1s 1 s
空间限制: 256MB 256 MB


裸的完全背包吧…
预处理招牌菜的价值就行了

#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
namespace fastIO{
    #define BUF_SIZE 100000
    #define OUT_SIZE 100000
    bool IOerror = 0;
    inline char nc(){
        static char buf[BUF_SIZE],*p1 = buf+BUF_SIZE, *pend = buf+BUF_SIZE;
        if(p1 == pend){
            p1 = buf; pend = buf+fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1){ IOerror = 1; return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline void read(int &x){
        bool sign = 0; char ch = nc(); x = 0;
        for(; blank(ch); ch = nc());
        if(IOerror)return;
        if(ch == '-') sign = 1, ch = nc();
        for(; ch >= '0' && ch <= '9'; ch = nc()) x = x*10+ch-'0';
        if(sign) x = -x;
    }
    inline void read(ll &x){
        bool sign = 0; char ch = nc(); x = 0;
        for(; blank(ch); ch = nc());
        if(IOerror) return;
        if(ch == '-') sign = 1, ch = nc();
        for(; ch >= '0' && ch <= '9'; ch = nc()) x = x*10+ch-'0';
        if(sign) x = -x;
    }
    #undef OUT_SIZE
    #undef BUF_SIZE
};
using namespace fastIO;
int n , m;
int T_max;
int t[2010] , w[2010] , T[2010] , W[2010];
ll f[5010];
void init()
{
    read(n);read(m);read(T_max);
    rep(i,1,n) read(t[i]),read(w[i]);
    rep(i,1,m) read(T[i]),read(W[i]);
    rep(i,1,m)
        rep(j,1,n)
        {
            int x;
            read(x);
            T[i] += x*t[j];
        }
    file(f);
    rep(i,1,n)
        rep(j,t[i],T_max)
            f[j] = max(f[j],f[j-t[i]]+w[i]);
    rep(i,1,m)
        rep(j,T[i],T_max)
            f[j] = max(f[j],f[j-T[i]]+W[i]);
    printf("%lld\n",f[T_max]);
}
int main()
{
    freopen("restaurant.in","r",stdin);
    freopen("restaurant.out","w",stdout);
    int T;read(T);
    while(T--) init();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值