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 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.
........
심플01 백팩으로 말이 필요 없습니다.
//poj 3624
//2013-04-12-16.51
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int dp[12900];
int w[3410];
int d[3410];
int main()
{
int n, m;
while (scanf("%d %d",&n, &m) != EOF)
{
for (int i = 1; i <= n; i++)
scanf("%d %d",&w[i], &d[i]);
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
{
for (int j = m; j >= w[i]; j--)
dp[j] = max(dp[j],dp[j-w[i]] + d[i]);
}
printf("%d
",dp[m]);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
poj 1976 A Mini Locomotive(가방 01)A train has a locomotive that pulls the train with its many passenger coaches. Therefore, the office of railroads decide...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.