YuntianZhao @ 2018-08-15 20:49:36
第十四个点要注意开 long long !
by 陌尘缘_怜 @ 2018-08-24 23:27:22
问题是开long long了 还是炸了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
void read(int &x);
struct food{
int a,b,c;
double s;
};
food f[55];
int n,t;
long long dp[100005];
bool cmp(food q,food w) {return q.s>w.s;}
int main()
{
read(t),read(n);
for(int i=1;i<=n;i++) read(f[i].a);
for(int i=1;i<=n;i++) read(f[i].b);
for(int i=1;i<=n;i++) read(f[i].c),f[i].s=(double)f[i].c/(double)f[i].b;
sort(f+1,f+n+1,cmp);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
for(int j=t;j>=0;j--)
{
if(j-f[i].c<0) continue;
dp[j]=max(dp[j],dp[j-f[i].c]+f[i].a-(t-j+f[i].c)*f[i].b);
}
}
long long maxn=-10000000;
for(int i=0;i<=t;i++) maxn=max(dp[i],maxn);
printf("%lld",maxn);
return 0;
}
void read(int &x)
{
x=0;
char c=getchar();
int i=1;
while(c<'0' or c>'9')
{
if(c=='-') i=-1;
c=getchar();
}
while(c>='0' and c<='9')
{
x=x*10+c-'0';
c=getchar();
}
x*=i;
}
by DuanYuFi @ 2018-08-28 15:34:06
@陌尘缘_怜 你的代码这一行
dp[j]=max(dp[j],dp[j-f[i].c]+f[i].a-(t-j+f[i].c)*f[i].b);
改成
dp[j]=max(dp[j],dp[j-f[i].c]+f[i].a-(long long int)((t-j+f[i].c)*f[i].b));
试一试 反正这个地方不改肯定是不对的,就是看这个强制转换加在哪里了
by 陌尘缘_怜 @ 2018-09-05 13:11:32
@DuanYuFi 谢谢啊
by WHL6666 @ 2018-10-18 21:09:16
谢谢!!!不开LL炸的..