题意
大赛将至,摆在你面前的是n道题目,第 i(1 ≤ i ≤ n) 道题目能提升 ai 点智力值,代码量为 bi KB,无聊值为 ci ,求至少提升m点智力值的情况下,所做题目代码量之和*无聊值之和最小为多少。
题解
像最小乘积树那么做就可以了
就是吧一个k**(我不会拼)的过程改成DP而已
别的就直接上模板就可以了
感觉这种求乘积的都可以这么做啊
很套路的感觉啊
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const LL MAX=1LL<<55;
const LL N=405;
LL n,m;
LL a[N],b[N],c[N];
LL d[N];
struct node{LL x,y;}s[N];
LL ans=MAX;
LL f[N][1005];//前i个,达到标准的最小值
bool g[N][1005];
node DP ()
{
for (LL u=0;u<=n;u++)
for (LL i=0;i<=800;i++)
f[u][i]=MAX;
f[0][0]=0;
for (LL u=0;u<n;u++)
for (LL i=0;i<=800;i++)
if (f[u][i]!=MAX)
{
if (f[u][i]+d[u+1]<f[u+1][i+a[u+1]])
{
f[u+1][i+a[u+1]]=f[u][i]+d[u+1];
g[u+1][i+a[u+1]]=true;
}
if (f[u][i]<f[u+1][i])
{
f[u+1][i]=f[u][i];
g[u+1][i]=false;
}
}
LL k=-1;
for (LL u=m;u<=800;u++)
if (f[n][u]!=MAX&&(k==-1||f[n][u]<f[n][k])) k=u;
// if (k==-1) return ;
node p;
p.x=0;p.y=0;
/* printf("d:");
for (int u=1;u<=n;u++) printf("%lld ",d[u]);
printf("\n");
printf("OZY:%lld\n",k);*/
for (LL u=n;u>=1;u--)
if (g[u][k])
{
k=k-a[u];
p.x+=b[u];
p.y+=c[u];
}
// printf("YES:%lld %lld\n",p.x,p.y);
ans=min(ans,p.x*p.y);
return p;
}
LL mul (node x,node y,node z)
{
LL x1=x.x-z.x,y1=x.y-z.y;
LL x2=y.x-z.x,y2=y.y-z.y;
return x1*y2-x2*y1;
}
void solve (node x,node y)
{
LL yy=x.y-y.y,xx=y.x-x.x;
for (LL u=1;u<=n;u++) d[u]=b[u]*yy+c[u]*xx;
node p=DP();
if (mul(p,x,y)>=0) return ;
solve(x,p);solve(p,y);
}
int main()
{
scanf("%lld%lld",&n,&m);
for (LL u=1;u<=n;u++) scanf("%lld%lld%lld",&a[u],&b[u],&c[u]);
for (LL u=1;u<=n;u++) d[u]=b[u];
node a=DP();
for (LL u=1;u<=n;u++) d[u]=c[u];
node b=DP();
solve(a,b);
printf("%lld\n",ans);
return 0;
}