zoukankan      html  css  js  c++  java
  • POJ 3624 Charm Bracelet

    Charm Bracelet

     

    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
     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int w[3500];
     9     int c[3500];
    10     int dp[13000];
    11     int n,V;
    12     while(scanf("%d%d",&n,&V)!=EOF)
    13     {
    14         memset(dp,0,sizeof(dp));
    15         for(int i=0;i<n;i++)
    16         {
    17             scanf("%d",&c[i]);
    18             scanf("%d",&w[i]);
    19         }
    20         for(int i=0;i<n;i++)
    21         for(int v=V;v>=0;v--)
    22         if(v-c[i]>=0)
    23         dp[v]=max(dp[v],dp[v-c[i]]+w[i]);
    24         printf("%d
    ",dp[V]);
    25     }
    26     return 0;
    27 }

  • 相关阅读:
    HTML5定位功能,实现在百度地图上定位
    很好用的API管理--Swagger
    依赖注入原理---IoC框架
    c# asp.net 修改webconfig文件 配置
    逗比的快钱支付
    MVC 5限制所有HTTP请求必须是POST方式
    富头像上传编辑器----很好用的上传照片和拍照功能
    .NET中的DES对称加密
    无聊搭1个框架
    PHP高效率写法
  • 原文地址:https://www.cnblogs.com/homura/p/4764316.html
Copyright © 2011-2022 走看看