求助求助!P1417烹调方案

P1417 烹调方案

忘无羡机 @ 2019-05-12 16:03:21

95分代码,哇了14号数据

#include<bits/stdc++.h> 
using namespace std;
int T,n,f[100010];
struct data
{
    int a,b,c;
};
data meal[100010];
bool cmp(data x,data y)
{
    return x.c * y.b < y.c * x.b;
}
int max(int a,int b)
{
    if(a > b)   return a;
    else return b;
}
int main()
{
    scanf("%d%d",&T,&n);
    for(int i = 1;i <= n;i ++)  scanf("%d",&meal[i].a);
    for(int i = 1;i <= n;i ++)  scanf("%d",&meal[i].b);
    for(int i = 1;i <= n;i ++)  scanf("%d",&meal[i].c);
    sort(meal + 1,meal + 1 + n,cmp);
    for(int i = 1;i <= n;i ++)
        for(int j = T;j >= meal[i].c;j --)
            f[j] = max(f[j],f[j - meal[i].c] + meal[i].a - j * meal[i].b);
    int ans = 0;
    for(int i = 1;i <= T;i ++)  
        ans = max(ans,f[i]);
    printf("%d",ans);
}

by 忘无羡机 @ 2019-05-12 16:03:55

数据范围问题吗


by _2222_ @ 2019-05-12 16:22:34

14答案是0

你的应该是野值


by 雨落星辰 @ 2019-07-12 12:05:32

把F数组int改为long long 把结构体内int改为long long


by 小小怪下士___ @ 2019-09-17 20:02:04

@忘无羡机 一时longlong一时爽,一直longlong一直爽


by 洪跃宁 @ 2020-12-20 21:46:22

@忘无羡机 真羡慕你,你WA了14号,我AC了14号...


|