P1782 旅行商的背包

#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

const int A = 1e7+10;
const int B = 1e7+10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for ( ; !isdigit(c); c = getchar()) if (c == '-') f = -1;
  for ( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  return x * f;
}

int n,m,C,cnt,w[B],v[B],f[B];



main()
{
    int a,b,s;
    n=read();m=read(),C=read();
    for (int i=1;i<=n;i++)
    {
        a=read(),b=read(),s=read(); 
        int r=1;
        while (s)
        {
            w[++cnt]=a*r;v[cnt]=r*b;s-=r;r<<=1;
            if (s<=r) 
            {w[++cnt]=a*s;v[cnt]=s*b;s=0;}
        }
    }
    
    for (int i=1;i<=cnt;i++)
        for (int j=C;j>=w[i];j--)
            f[j]=max(f[j],f[j-w[i]]+v[i]);
    
    for (int i=1;i<=m;i++)
    {
        int a,b,c;
        a=read(),b=read(),c=read();
        for (int j=C;j>=0;j--)
        {
            for(int k = 0; k <= j; k++)
                f[j]=max(f[j],f[j-k]+a*k*k+b*k+c);
        }
    }
    
    printf("%lld",f[C]);
}

posted @ 2021-03-14 20:49  zxsoul  阅读(39)  评论(0编辑  收藏  举报