zcmu 2165 黄金矿工

【题目】


Sample Input

3 10 

1 1 1 1 

2 2 2 2 

1 3 15 9

3 10

1 1 13 1

2 2 2 2

1 3 4 7

Sample Output

3

7

HINT

30%的数据,0 < T ≤ 4000 

100%的数据,N ≤ 200, 0 < T ≤ 40000 

【代码】

#include<bits/stdc++.h>
using namespace std;
int dp[40005];
struct p
{
    int t,v;
    double d;
}f[205];
bool cmp(p a,p b)
{
    return a.d<b.d;
}
int main()
{
    int n,m,x,y,i,j;
    memset(dp,0,sizeof(dp));
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d%d%d%d",&x,&y,&f[i].t,&f[i].v);
        f[i].d=x*1.0/y;
    }
    sort(f,f+n,cmp);
    for(i=0;i<n;i++)
    {
        if(f[i].d==f[i-1].d)
            f[i].t+=f[i-1].t;
        for(j=m;j>=f[i].t;j--)
            dp[j]=max(dp[j],dp[j-f[i].t]+f[i].v);
    }
    printf("%d\n",dp[m]);
    return 0;
}

【不知道什么】

还记得那天晚上训练赛,看到队友说咦就是简单的背包,我一乐,然后发现,老子不会。


拖了这么久终于补上,只是还是不太能搞懂,再给我点时间吧QAQ。



猜你喜欢

转载自blog.csdn.net/qq_41117236/article/details/80644496