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 }

  • 相关阅读:
    【Linux 日常】设置动态链接库目录
    某站视频python抓取: m3u8转mp4
    GDB 主要调试命令
    算法【查找一】
    算法【排序四】
    算法【排序三】
    Vim常用命令整理
    【OpenCV】贝叶斯之肤色分割模型
    算法【排序二】
    算法【排序一】
  • 原文地址:https://www.cnblogs.com/homura/p/4764316.html
Copyright © 2011-2022 走看看