设为首页 加入收藏

TOP

POJ3624Charm Bracelet(01背包)
2015-07-20 17:56:58 来源: 作者: 【 】 浏览:4
Tags:POJ3624Charm Bracelet 背包
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 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.

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

Source

还是01背包

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         using namespace std; int main() { int n,i,j,v; while(scanf("%d%d",&n,&v)!=EOF){ int dp[13000]={0},c[3500],w[3500]; for(i=0;i
        
         =c[i];j--) { if(dp[j]
          
          


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 4923 Room and Moor 贪心+栈 下一篇C++中为啥ifstream不用new,用完..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: