poj3624 01背包
来源:互联网 发布:人工智能平台有哪些 编辑:程序博客网 时间:2024/06/05 06:54
Charm Bracelet
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 23 Accepted Submission(s) : 9
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 theN (1 ≤N ≤ 3,402) available charms. Each charmi in the supplied list has a weightWi (1 ≤Wi ≤ 400), a 'desirability' factorDi (1 ≤Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more thanM (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.
* 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 andDi
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
4 61 42 63 122 7
23
做这道题的时候多亏了Min的帮助不然自己也不理解,01背包,完全背包,多重背包
在背包九讲都很清楚
#include<stdio.h>#include<string.h>int m,n,i,j,w[3412],p[3412],c[12892];int main(){memset(w,0,sizeof(w));memset(p,0,sizeof(p));memset(c,0,sizeof(c));scanf("%d%d",&n,&m);for(i=1;i<=n;i++)scanf("%d%d",&w[i],&p[i]);for(i=1;i<=n;i++)for(j=m;j>=0;j--)//这里应该注意一下01背包跟完全背包的区别{if(j>=w[i]){if(c[j]<p[i]+c[j-w[i]])c[j]=p[i]+c[j-w[i]];elsec[j]=c[j];}}printf("%d\n",c[m]);return 0;}
- poj3624--01背包
- POJ3624 01背包
- poj3624 dp 01背包
- 1poj3624(01背包)
- poj3624--01背包
- poj3624(01背包)
- 01背包-poj3624
- poj3624 01背包
- POJ3624(01背包问题)
- 01背包poj3624
- poj3624 01背包
- POJ3624 01背包问题
- POJ3624 01背包
- POJ3624--01背包
- poj3624 01背包
- poj3624 01背包
- POJ3624 01背包
- POJ3624——01背包
- html5 视频和音乐播放器标签属性
- C++设计模式---桥接模式—合成/聚合复用原则
- ORALCE控制文件
- 1.点亮1个led程序分析(汇编)
- GetTickCount() 函数的作用和用法
- poj3624 01背包
- Linux设备驱动之I/O端口与I/O内存
- MFC加入滚动条
- 快速排序算法
- 大小为0的数组
- getch() vs getchar()
- uestc OJ 1849Negative People in Da House
- CKEditor+CKFinder配置以及使用简介
- extern "C"的作用