openjudge charm bracelet
2015-12-02 17:09
585 查看
7113:Charm Bracelet
查看提交
统计
提问
总时间限制: 1000ms 内存限制: 65536kB
描述
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 iin 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.
输入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
输出Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
样例输入
4 6 1 4 2 6 3 12 2 7
样例输出
23
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,i,j;
int f[12888],w[3420],v[3420];
int main()
{
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++)
scanf("%d%d",&w[i],&v[i]);
memset(f,0,sizeof(f));
for (i=1;i<=n;i++)
for (j=m;j>=w[i];j--)
f[j]=max(f[j],f[j-w[i]]+v[i]);
cout<<f[m];
return 0;
}
//此题为标准的01背包
相关文章推荐
- MySQL-MMM实现MySQL高可用
- Linux-CenterOS在线yum 安装MySql
- 虚拟机安装linux,版本选择只有32位的问题
- linux alarm函数解除read write等函数的阻塞
- linux安装LNMP的资源
- LINUX驱动之SPI子系统之四spi_master的注册流程
- Photoshop CC (2015.1) 2015.11.30版
- 修改方法内容,不重启tomcat服务器
- openjudge开餐馆
- linux工具:ssh---未完
- js架构设计模式——MVC,MVP 和 MVVM 的图示及简单明了的区别说明
- k-近邻算法(KNN)--2改进约会网站的配对效果---by香蕉麦乐迪
- 电子小制作:一个远程温度湿度监控方案
- Maven Dependency Scope
- 新手福利:Apache Spark 入门攻略
- Linux——琐碎
- js架构设计模式——你对MVC、MVP、MVVM 三种组合模式分别有什么样的理解?
- Linux- 线程函数如何将返回值传给主线程
- Nginx 新特性reuseport
- linux如何查看一个进程的堆栈