Charm Bracelet(poj3624)(01背包)

Charm Bracelet

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 24165   Accepted: 10898

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 weightWi (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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int i,j,n,m;
	int a[3500],b[3500],dp[13000];
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		for(i=1;i<=n;i++)
		{
			scanf("%d %d",&a[i],&b[i]);
		}
		memset(dp,0,sizeof(dp));
		for(i=1;i<=n;i++)
		{
			for(j=m;j>=a[i];j--)
			dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
		}
		printf("%d\n",dp[m]);
	}
	return 0;
}

时间: 2024-11-19 00:24:27

Charm Bracelet(poj3624)(01背包)的相关文章

Charm Bracelet(01背包)

Problem 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 

POJ3624 Charm Bracelet 【01背包】

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22621   Accepted: 10157 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 fro

POJ 3624 Charm Bracelet(01背包模板)

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45191   Accepted: 19318 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 fro

POJ 3624 Charm Bracelet【01背包】

解题思路:直接套公式就能做的01背包, for(i=1;i<=n;i++) { for(v=w[i];v<=m;v++) f[i,v]=max(f[i,v],f[i-1,v-w[i]]+d[i]);//只想明白了可以用一维数组来存放包的价值,因为我们需要的只是包的最大价值,不用记录是第几个包的时候,有最大价值,然后v从w[i]到包的总容量循环不明白. } for(i=1;i<=n;i++) { for(v=m;v>=c[i];v--) //即最开始给定包的总容量(此时包是空的),循

poj3624 01背包入门 dp+滚动数组

poj3624 01背包 dp+滚动数组 Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25458   Accepted: 11455 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 bes

POJ3624Charm Bracelet(01背包)

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23359   Accepted: 10532 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 fro

poj3624 0-1背包

1 //Accepted 240 KB 188 ms 2 //0-1背包 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 using namespace std; 7 const int imax_n = 3405; 8 const int imax_m = 12885; 9 int f[imax_m]; 10 int weight[imax_n]; 11 int factor[imax_

POJ 3624 Charm Bracelet (01)(背包入门)

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 

POJ3624 Charm Bracelet(典型01背包问题)

Time Limit: 1000MS          Memory Limit: 65536K          Total Submissions: 32897          Accepted: 14587 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 poss

POJ3624(01背包:滚动 实现)

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30417   Accepted: 13576 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 fro