POJ 2642 Charm Bracelet

简介:

题解:01背包的入门题 不知道为什么二维数组RE了 所以一维滚动数组可以A掉

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int dp[13000];
int cost[13000],rating[13000];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=0;i<=m;i++)
        dp[i]=0;
        for(int i=1;i<=n;i++)
        cin>>cost[i]>>rating[i];
        for(int i=1;i<=n;i++)
            for(int j=m;j>=cost[i];j--)
            dp[j]=max(dp[j],dp[j-cost[i]]+rating[i]);
        cout<<dp[m]<<endl;
    }
    return 0;
}


 

目录
相关文章
|
6月前
Knight Moves(POJ2243)
Knight Moves(POJ2243)
poj 3624 Charm Bracelet(简单01背包)
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.
38 0
洛谷P2871-[USACO07DEC]Charm Bracelet S(01背包模板题)
洛谷P2871-[USACO07DEC]Charm Bracelet S(01背包模板题)
洛谷P2871-[USACO07DEC]Charm Bracelet S(01背包模板题)
POJ-2488,A Knight's Journey(DFS)
POJ-2488,A Knight's Journey(DFS)
hdu-1098 Ignatius's puzzle(费马小定理)
hdu-1098 Ignatius's puzzle(费马小定理)
154 0
hdu-1098 Ignatius's puzzle(费马小定理)
POJ-3624,Charm Bracelet(01背包)
POJ-3624,Charm Bracelet(01背包)
|
测试技术
HDU-1026,Ignatius and the Princess I(BFS+打印路径)
HDU-1026,Ignatius and the Princess I(BFS+打印路径)
HDU-1027,Ignatius and the Princess II
HDU-1027,Ignatius and the Princess II
PKU 3624 Charm Bracelet
本文主要讲背包入门题