当前位置:网站首页>F - Charm Bracelet
F - Charm Bracelet
2022-06-26 12:40: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背包
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;
}
边栏推荐
- 710. random numbers in the blacklist
- Accumulation of interview questions
- Redis learning - 04 persistence
- 记一次phpcms9.6.3漏洞利用getshell到内网域控
- 倍福通过CTU和TON实现时间片大小和数量的控制
- 中科软外包一面
- Less than 40 lines of code to create a blocprovider
- Detailed explanation of C const: definition and use of C constant
- Websocket and socket IO case practice
- Guacamole installation
猜你喜欢

processing 随机生成线动画

倍福Ethercat模块网络诊断和硬件排查的基本方法

倍福将EtherCAT模块分到多个同步单元运行--Sync Units的使用

倍福PLC通过MC_ReadParameter读取NC轴的配置参数

File remote synchronization and backup artifact Rsync

Less than 40 lines of code to create a blocprovider

倍福PLC通过程序获取系统时间、本地时间、当前时区以及系统时间时区转换

【Spark】.scala文件在IDEA中几种图标的解释
RSS rendering of solo blog system failed

Beifu PLC passes MC_ Readparameter read configuration parameters of NC axis
随机推荐
Photoshop 2022 23.4.1增加了哪些功能?有知道的吗
倍福NC轴状态转移图解析
Angle de calcul POSTGIS
P2393 yyy loves Maths II
[geek challenge 2019] rce me 1
System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
goto语句实现关机小程序
别乱用 FULL_CASE 和 PARALLEL_CASE
倍福TwinCAT3实现CSV、TXT文件读写操作
A must for programmers, an artifact utools that can improve your work efficiency n times
Vivado 错误代码 [DRC PDCN-2721] 解决
国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
EasyGBS如何解决对讲功能使用异常?
Summary of some application research cases of UAV Remote Sensing in forest monitoring
solo 博客系统的 rss 渲染失败
Tiger DAO VC产品正式上线,Seektiger生态的有力补充
processing 随机生成线动画
Less than 40 lines of code to create a blocprovider
自定义封装下拉组件
倍福通过CTU和TON实现时间片大小和数量的控制