假期训练——POJ - 3624 Charm Bracelet DP+0-1背包
来源:互联网 发布:琳琅怎么绑定淘宝账号 编辑:程序博客网 时间:2024/06/10 05:56
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.
* 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 61 42 63 122 7
23
典型的0-1背包问题
#include <iostream> #include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <climits>#include <cstring>#include <string>#include <set>#include <map>#include <queue>#include <stack>#include <vector>#include <list>#define rep(i,m,n) for(int i=m;i<=n;i++)#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)const int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1e10+7#define pb push_back#define mp make_pair#define fi first#define se second#define pi acos(-1.0)#define pii pair<int,int>#define Lson L, mid, rt<<1#define Rson mid+1, R, rt<<1|1const int maxn=5e2+10;using namespace std;typedef vector<int> vi ;typedef long long ll;typedef unsigned long long ull; inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}//#pragma comment(linker, "/STACK:102400000,102400000")ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}int maxx(int x,int y){return x>y?x:y;}int dp[2][12881];int n,m;int w[3403];int d[3403];int main(){string s;ios::sync_with_stdio(false);cin >> n>>m;for(int i=1;i<=n;i++){cin >> w[i] >> d[i];}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){dp[(i)%2][j] = dp[(i-1)%2][j];if(j-w[i]>=0){dp[i%2][j] =maxx(dp[(i-1)%2][j],dp[(i-1)%2][j-w[i]]+d[i]);}}}cout<<dp[n%2][m]<<endl;return 0;}
- 假期训练——POJ - 3624 Charm Bracelet DP+0-1背包
- poj 3624 Charm Bracelet(0-1背包~DP~)
- poj 3624 Charm Bracelet DP 0/1 背包问题
- POJ 3624 Charm Bracelet (线性dp 0/1背包)
- poj 3624 Charm Bracelet(0-1背包 DP)
- POJ - 3624 《Charm Bracelet》 【0-1背包】
- POJ 3624 Charm Bracelet(0,1背包)
- POJ 3624 Charm Bracelet 0-1背包
- 【0-1背包】-POJ-3624-Charm Bracelet
- POJ 3624 Charm Bracelet 【0 1背包】
- POJ 3624 Charm Bracelet 0 1 背包
- poj 3624 Charm Bracelet DP 01背包
- POJ 3624 Charm Bracelet 【DP】【01背包】
- POJ.3624 Charm Bracelet(DP 01背包)
- Charm Bracelet —— 0-1背包
- POJ-3426-0-1背包Charm Bracelet
- POJ-3624-Charm Bracelet-简单0/1背包、动态规划、DP
- POJ 3624 Charm Bracelet(0-1背包)
- 战舰v3|stm32f103 摄像头OV2640驱动程序
- ubuntu 选择就内核启动
- 线性表之链队列
- 反转链表
- [51nod 1362]搬箱子 组合数公式
- 假期训练——POJ - 3624 Charm Bracelet DP+0-1背包
- display: flex ,Flex是Flexible Box的缩写,意为"弹性布局"
- 关于Andorid的第三方库导入和其他知识
- **LeetCode 467. Unique Substrings in Wraparound String
- 【chrome】chrome下载离线安装包
- 使用Async进行异步操作,先回复,后操作
- [BZOJ4710][Jsoi2011]分特产 容斥原理
- 假期训练——CodeForces - 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses DP+dfs
- 队列操作 ——蓝桥杯