当前位置:网站首页>F - Charm Bracelet
F - Charm Bracelet
2022-06-26 13:08:00 【YJEthan】
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 weight Wi (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.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di
Output
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
Sample Input
4 6 1 4 2 6 3 12 2 7
Sample Output
23
01 knapsack
dp[I][j]=max(dp[I][j],dp[I][j-w[I]]+d[I])
#include<stdio.h>
#include<string.h>
int max(int a,int b)
{
if(a>b) b=a;
return b;
}
int main()
{
int n,m,i,j;
int w[20000],d[20000],dp[20000];
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%d%d",&w[i],&d[i]);
}
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
{
for(j=m;j>=w[i];j--)
{
dp[j]=max(dp[j],dp[j-w[i]]+d[i]);
}
}
printf("%d\n",dp[m]);
}return 0;
}
边栏推荐
- Processsing 鼠标交互 学习
- Summary of wechat applet test points
- 【网络是怎么连接的】第二章(中):一个网络包的发出
- 享元模式(Flyweight)
- Electron official docs series: Best Practices
- Goto statement to realize shutdown applet
- System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
- find及du -sh显示权限不够的解决方法
- Appearance mode (facade)
- QT .pri 的建立与使用
猜你喜欢
倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用
Group counting practice experiment 9 -- using cmstudio to design microprogram instructions based on segment model machine (2)
外观模式(Facade)
Deeply analyze the differences between dangbei box B3, Tencent Aurora 5S and Xiaomi box 4S
Explain C language 10 in detail (C language series)
Don't mess with full_ Case and parallel_ CASE
[geek challenge 2019] rce me 1
黑马笔记---常用API
Power Designer - Custom Comment button
Photoshop 2022 23.4.1增加了哪些功能?有知道的吗
随机推荐
[geek challenge 2019] rce me 1
复制多个excel然后命名不同的名字
Angle de calcul POSTGIS
利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
[esp32-c3][rt-thread] run RT-Thread BSP minimum system based on esp32c3
Detailed explanation of C const: definition and use of C constant
Learning Processing Zoog
第十章 设置结构化日志记录(二)
倍福NC轴状态转移图解析
UVA5009 Error Curves三分
外观模式(Facade)
10秒内完成火灾预警,百度智能云助力昆明官渡打造智慧城市新标杆
P5733 [deep foundation 6. example 1] automatic correction
Accumulation of interview questions
PostGIS calculation angle
National standard gb28181 protocol easygbs cascaded universal vision platform, how to deal with live message 403?
倍福PLC旋切基本原理和应用例程
Go structure method
Record a phpcms9.6.3 vulnerability to use the getshell to the intranet domain control
倍福TwinCAT通过Emergency Scan快速检测物理连接和EtherCAT网络