zoukankan      html  css  js  c++  java
  • hdu2602 DP (01背包)

    题意:有一个容量 volume 的背包,有一个个给定体积和价值的骨头,问最多能装价值多少。

    经典的 01 背包问题不谈,再不会我就要面壁了。

    终于有一道题可以说水过了 ……心好累

     1 #include<stdio.h>
     2 #include<string.h>
     3 #define max(a,b) a>b?a:b
     4 
     5 int va[1005],vo[1005],dp[1005];
     6 
     7 int main(){
     8     int T;
     9     while(scanf("%d",&T)!=EOF){
    10         for(int q=1;q<=T;q++){
    11             memset(dp,0,sizeof(dp));
    12             int n,v;
    13             int i,j,ans=0;
    14             scanf("%d%d",&n,&v);
    15             for(i=1;i<=n;i++)scanf("%d",&va[i]);
    16             for(i=1;i<=n;i++){
    17                 scanf("%d",&vo[i]);
    18                 for(j=v;j>=vo[i];j--){
    19                     dp[j]=max(dp[j],dp[j-vo[i]]+va[i]);
    20                     ans=max(dp[j],ans);
    21                 }
    22             }
    23             printf("%d
    ",ans);
    24         }
    25     }
    26     return 0;
    27 }
    View Code
  • 相关阅读:
    Remove Element
    Binary Tree Inorder Traversal
    Symmetric Tree
    Roman to Integer
    Search Insert Position
    Reverse Integer
    Pascal's Triangle
    Merge Sorted Array
    Same Tree
    Visual Studio Code 做PHP开发
  • 原文地址:https://www.cnblogs.com/cenariusxz/p/4309581.html
Copyright © 2011-2022 走看看