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下的防火墙iptables
    oracle 学习
    关于测试计划制定
    Android APP性能测试笔记(一)
    adb报错问题解决方法
    Android studio安装与配置
    领导能力与领导力
    ADB安装及使用
    Advanced-REST-client
    性能测试体系-测试分析及调优
  • 原文地址:https://www.cnblogs.com/homura/p/4764316.html
Copyright © 2011-2022 走看看