CRB and His Birthday(2015多校)

原题链接http://acm.hdu.edu.cn/showproblem.php?pid=5410

因为他每买一件物品就会得到Ai颗糖,每买一种物品就会得到Bi颗糖。有两个价值。。所以我们应该先用一次01背包把两个价值统一起来。。。因为01背包中每种物品只能取一次。。。。然后我们用多重背包来决定应该多买哪种物品得到的糖果最多。。。。==

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1010;
__int64 dp[2010];
int w[maxn],a[maxn],b[maxn];
int main()
{
    int t,n,W;
    scanf("%d",&t);
    while(t--)
    {
        memset(dp,0,sizeof(dp));
        int i,j;
        scanf("%d%d",&W,&n);
        for(i=1;i<=n;i++)
        scanf("%d %d %d",&w[i],&a[i],&b[i]);
        for(i=1;i<=n;i++)
        {
            for(j=W;j>=w[i];j--)
            {
                dp[j]=max(dp[j],dp[j-w[i]]+a[i]+b[i]);
            }
        }
        for(i=1;i<=n;i++)
        {
            for(j=0;j<=W;j++)
            {
            if(j>=w[i])
            dp[j]=max(dp[j],dp[j-w[i]]+a[i]);
           }
        }
        printf("%I64d\n",dp[W]);
    }
    return 0;
} 
时间: 2024-08-02 06:47:59

CRB and His Birthday(2015多校)的相关文章

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也

hdu 5288||2015多校联合第一场1001题

http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i

hdu5289||2015多校联合第一场1002贪心+RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to

hdu5348(2015多校5)--MZL&#39;s endless loop(搜索)

题目链接:点击打开链接 题目大意:给出n个点,m条无向边,现在要求将无向边变为有向边,要保证每个点的出度和入度的差不超过1 直接进行搜索,对每个点进行出度和入度的判断,如果出度大,就先进行反向的搜索(每搜索一条边u,v就认为这是一条v到u的有向边),反之,进行正向搜索(每搜到一条边u,v认为这是一条u到v的有向边),一直搜索到找不到边能继续为止. 注意: 1.已经使用过的边为了防止再次被遍历,可以修改head,head[u] = edge[i].next 2.注意自环,因为搜索是判断能不能继续向

hdu5379||2015多校联合第7场1011 树形统计

http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is an artist. Today he is playing mahjong alone. He suddenly feels that the tree in the yard doesn't look good. So he wants to decorate the tree.(The tree has n vertexs, i

hdu5351(2015多校5)--MZL&#39;s Border(打表,,找规律)

题目链接:点击打开链接 题目大意:给出b1 = 'b' , b2 = 'a' , bi = b(i-1)b(i-2),将i-1和i-2链接起来,记录一个串的s[1-i] 和s[n-i+1-n]相同的话 Border,当i为最长是为LBorder,现在给让求在bn这个串上的前m个字符组成的子串的LBorder 通过计算可以发现,b字符串的前缀都是相同的,所以只要求出m的LBorder就行,和n是无关的,打表找出规律,找出对应不同的m,LBorder的值,因为存在大数,用java写 dp[i]第i层

hdu5353||2015多校联合第六场1001 贪心

http://acm.hdu.edu.cn/showproblem.php?pid=5353 Problem Description There are n soda sitting around a round table. soda are numbered from 1 to n and i-th soda is adjacent to (i+1)-th soda, 1-st soda is adjacent to n-th soda. Each soda has some candies

2015 多校 #5 1005 MZL&#39;s chemistry

MZL's chemistry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1306    Accepted Submission(s): 601 Problem Description MZL define F(X) as the first ionization energy of the chemical element X N