HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2191

多重背包问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Tanky Woo
// HDOJ 2191
 
#include <iostream>
using namespace std;
 
int nCases;
int nValue, nKind;
int value[105], weight[105], bag[105];
int nMultiplePack[105];
 
int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &nCases);
    while(nCases--)
    {
        memset(nMultiplePack, 0, sizeof(nMultiplePack));
        scanf("%d %d", &nValue, &nKind);
        for(int i=0; i<nKind; ++i)
            scanf("%d %d %d", &value[i], &weight[i], &bag[i]);
        for(int i=0; i<nKind; ++i)
            for(int j=0; j<bag[i]; ++j)
                for(int k=nValue; k>=value[i]; --k)
                    if(nMultiplePack[k] < nMultiplePack[k-value[i]]+weight[i])
                        nMultiplePack[k] = nMultiplePack[k-value[i]] + weight[i];
        printf("%d\n", nMultiplePack[nValue]);
 
    }
    return 0;
}

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

《HDOJ 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活》有6个想法

  1. I have been looking out good information about this subject for a while and I gotta say you put up gives me some general thought about my paper I am gonna write for my assignment. I would love copy some of your words here and I hope you don’t mind. Thanks. I will reference your work of course. Thank you.Maintain updating the good posts. will come back.

发表评论

电子邮件地址不会被公开。 必填项已用*标注