NOIP2001 普及组 装箱问题

标准的01背包,就不写分析了,标准就看 我的背包问题的解析

 

 

/*
* =====================================================================================
*
* Filename: noippujizhuangxiang.c
*
* Description: RT
*
* Version: 1.0
* Created: 2014-05-19 15:44:57
* Revision: none
* Compiler: gcc
*
* Author: Rainboy (mn), 597872644@qq.com
* Company: NONE
*
* =====================================================================================
*/
#include <stdio.h>
int a[20001]={0};
int V,numofwupin=0;
int b[30]={0};

int main(int argc, const char *argv[])
{
scanf("%d",&V);
scanf("%d",&numofwupin);
int i,j,k,l;
for (i = 0; i < numofwupin; i++) {
scanf("%d",&b[i]);
}

for (j = 0; j < numofwupin; j++) {
for (i = V; i >0; i--) {
if((b[j]<=i) &&(b[j]+a[i-b[j]] > a[i]))
a[i]= b[j] + a[i-b[j]];
}
}
printf("%d\n",V-a[V]);


return 0;
}

 

  

posted @ 2014-05-19 16:16  rainboy  阅读(482)  评论(0)    收藏  举报