4131:Charm Bracelet
来源:互联网 发布:droid4x mac 安装失败 编辑:程序博客网 时间:2024/06/05 18:43
4131: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>using namespace std;//http://bailian.openjudge.cn/practice/4131///简单的01背包问题,简单题我总是会出错,还总是会错在特别简单的地方 int n,m,w[3600],d[3600];int dp[3600][13100];void f(){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(w[i]<=j){ dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+d[i]); } else{ dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } } cout<<dp[n][m]<<endl;}int main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>w[i]>>d[i]; } f();}
- 4131:Charm Bracelet
- POJ 4131 Charm Bracelet
- 百炼:4131:Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- Charm Bracelet
- poj 3624 Charm Bracelet
- poj3624 Charm Bracelet
- poj 3624 Charm Bracelet
- Java 集合List、Set、Map特性总结
- Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect)
- Android 加壳尝试(一)
- Less介绍及其与Sass的差异
- Android 持久化技术
- 4131:Charm Bracelet
- SQL语句使用01----where常用等
- 简易的XListView下拉加载和上拉刷新
- centos7安装MongoDB3.4 以及spring data mongodb的配置使用
- 简述request.getRequestDispatcher(url)与response.sendRedirect(url)的区别
- 矩阵乘法+快速幂——【模板】矩阵快速幂
- git使用
- PAT (Advanced) 1010. Radix (25)
- poj2559---Largest Rectangle in a Histogram(单调栈)