前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >poj 3624 Charm Bracelet(简单01背包)

poj 3624 Charm Bracelet(简单01背包)

作者头像
xindoo
发布2021-01-22 14:58:08
4630
发布2021-01-22 14:58:08
举报
文章被收录于专栏:XINDOO的专栏

题目链接

Description

Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weightWi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).

Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.

。。。。。。。。

简单01背包,无需多言。

代码语言:javascript
复制
//poj 3624 
//2013-04-12-16.51
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int dp[12900];
int w[3410];
int d[3410];

int main()
{
    int n, m;
    while (scanf("%d %d",&n, &m) != EOF)
    {
        for (int i = 1; i <= n; i++)
            scanf("%d %d",&w[i], &d[i]);
        memset(dp, 0, sizeof(dp));
        for (int i = 1; i <= n; i++)
        {
            for (int j = m; j >= w[i]; j--)
                dp[j] = max(dp[j],dp[j-w[i]] + d[i]);
        }
        printf("%d\n",dp[m]);
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013-04-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档