Title address http://acm.hdu.edu.cn/showproblem.php?pid=2602

#include <stdio.h>
#include <string.h>
int main()
{
int cost[],f[],va[];
int i,j,k,n,m;
scanf("%d",&k);
while(k--)
{
memset(f,,sizeof(f));
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
scanf("%d",&va[i]);
for(i=;i<n;i++)
scanf("%d",&cost[i]);
for(i=;i<n;i++)
{ for(j=m;j>=cost[i];j--)
{ // Classic part
f[j]=f[j]>f[j-cost[i]]+va[i]?f[j]:f[j-cost[i]]+va[i];// Put it or not
}
}
printf("%d\n",f[m]);
}
return ;
}

Dynamic planning 0-1 Add this picture to the classic knapsack problem in order to understand

hdu 0-1 More articles about backpacks

  1. HDU 1011 Tree backpack (DP) Starship Troopers

    Topic link :  HDU 1011 Tree backpack (DP) Starship Troopers The question :  There are some rooms on the map , Every room has a certain bugs And get it brains The probability value of , One person leads m An army team from the entrance ( room ...

  2. Big Event in HDU( Multiple backpack templates )

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Java/Othe ...

  3. hdu 5445 Multiple backpack

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

  4. hdu 1203 01 knapsack I need a offer

    hdu 1203  01 knapsack  I need a offer Topic link :http://acm.hdu.edu.cn/showproblem.php?pid=1203 The main idea of the topic : Give you every school gets offe ...

  5. poj1417 Take the right and check the collection +0/1 knapsack

    The question : There is an island inhabited by gods and Demons , And we know the number of gods and Demons , Now it is known that God always speaks the truth , The devil is always telling lies , Yes n A asked , Ask a God or a devil ( Unknown identity ), The question is whether someone is a God or a devil , According to their answers , Ask if you can determine which are gods and which are ...

  6. P1417 Cooking plan (0/1 knapsack + greedy )

    Background Thanks to your help , Mars suffered only the smallest loss . but gw I'm too lazy to rebuild my home , We built a spaceship to fly to distant places earth star . But it's halfway there ,gw Found a very serious problem : i'm hungry ~ gw I can still cook , So he took out the storage ...

  7. Luogu P1064 Jin Ming's budget ( Dependent 0/1 knapsack )

    Title Description Jin Ming is very happy today , The key to the new house is needed , In the new room, there is a very spacious room for Jin Ming himself . What makes him more happy is , Mother said to him yesterday :“ What items do you need to buy in your room , How to arrange , It's up to you , As long as it doesn't exceed NN Yuan is fine ”. ...

  8. POJ 1636 Prison rearrangement DFS+0/1 knapsack

    Topic link : id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS   Memor ...

  9. hdu 1114( Completely backpack )

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  10. POJ 1745 【0/1 knapsack 】

    Topic link :http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

Random recommendation

  1. SQL IN The operator 、SQL BETWEEN The operator 、SQL Alias( Alias )

    IN The operator IN The operator allows us to WHERE Multiple values specified in clause . SQL IN grammar SELECT column_name(s) FROM table_name WHERE column_name ...

  2. MVC Interceptors record user logs of operations

    It is mainly used to record the dynamic operation of users , public class OperationAttribute:ActionFilterAttribute { /// <summary> /// Method name ...

  3. adjustment busybox in syslogd Read the kernel printk Message length

    busybox The default read kernel printk Message length 256, adopt CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE Macro can be adjusted , as follows : #cd busybox-1.21.1#m ...

  4. Ubuntu Under the quick installation php Environmental Science

    The egg hurt a little today , stay Ubuntu I've got a little bit of undergarment php Environment , That is to say, I installed it MySQL.PHP.Apache. It's really simple ... Can't help but remind me of the original in windows I just can't install it when I develop it , And one is just a few G ...

  5. model Encapsulation +MJExtension Convenient for subsequent processing

    //  Basic model #import <Foundation/Foundation.h> @interface BasicDataModel : NSObject - (id)initWith ...

  6. Core Motion Sensor raw data

    1. Visit the original Motion data #import <UIKit/UIKit.h> #import <CoreMotion/CoreMotion.h> @interface Vie ...

  7. Myeclipse Customize java Code shortcuts

    1. First, in the MyEclipse The menu bar finds "windows" Drop down menu to find preferences ( english Prefenerces), The preferences screen pops up .   2. open java -->editor---& ...

  8. Learn jQuery in y seconds

    [ compatible IE8 There's no way ][ It's not Modern Web( Direct operation is not recommended DOM) But it's also a sharp weapon ] Personal references [CSS Website record ][JavaScript Dom Programming art ][ At the beginning, we can't be too entangled in mechanism, because ...

  9. js object-oriented 、 Create factory patterns for objects 、 Constructor Pattern 、 Prototype chain mode

    JS object-oriented programming ( Reprint ) What is object-oriented programming (OOP)? Write code with the idea of object , It's object-oriented programming . The characteristics of object-oriented programming abstract : Get to the core encapsulation : Methods can only be accessed through objects Inherit : Inherit a new object from an existing object ...

  10. Java Single producer consumer problem

    package com.cwcec.test; class Resource { private int count = 0; private boolean flag = false; public ...