poj3624--01背包
来源:互联网 发布:知乎 韦小宝最喜欢谁 编辑:程序博客网 时间:2024/06/07 09:48
今天背包入门了噢~~其实挺开心的啦~~
嘿嘿,虽然题目比较简单,但还是小小的成就感~
这就是算法的乐趣吧~~
加油!!!
#define LOCAL#include <stdio.h>#include <string.h>#include <stdlib.h> #define MAXN 3500 + 10#define MAX 13800 + 10int dp[MAX];int item[MAXN][2];int main(){#ifdef LOCALfreopen("C:\\Users\\Administrator\\Desktop\\Temp\\ACMTempIn.txt", "r", stdin);//freopen("C:\\Users\\Administrator\\Desktop\\Temp\\ACMTempOut.txt", "w", stdout);#endifint quantity, cubage;int i = 0,j;int max;while(scanf("%d%d", &quantity, &cubage) != EOF){//数据输入for(i = 0; i < quantity; i++){scanf("%d%d", &item[i][0], &item[i][1]);}//构造dp数组//初始化memset(dp, 0, sizeof(dp));for(i = 0; i <= cubage; i++){if(i >= item[quantity - 1][0])dp[i] = item[quantity - 1][1];}//枚举物品for(i = quantity - 2; i >= 0; i--){//更新dp数组for(j = cubage; j > 0; j--){if(j >= item[i][0] && dp[j - item[i][0]] + item[i][1] > dp[j])dp[j] = dp[j - item[i][0]] + item[i][1];}}//找到最大数max = 0;for(i = 0; i <= cubage; i++){if(dp[i] > max)max = dp[i];}printf("%d\n", max);}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背包
- 静态、共享和动态库
- ASP.NET 回发详解
- Linux开启FTP(vsftpd)服务
- Android.mk文件语法规范
- 如何查看MAC地址
- poj3624--01背包
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 带有xml转发的select非阻塞,修正了一个错误
- Linux vsftpd的配置
- linux C/C++之库编译静态库、共享库
- 入户深圳的五种方式
- myeclipse8.5 如何设置自动提示
- 内核中的container_of的实现
- strcpy与strncpy