poj 3624
来源:互联网 发布:赵洪文国 知乎 编辑:程序博客网 时间:2024/05/29 18:05
1. 地址
http://poj.org/problem?id=3624
2. 定位
动态规划
0-1背包
3. 分析
典型0-1背包,具体思路见 hdu 2602。
4. 代码
#include <stdio.h>#include <stdlib.h>int weight[3403];int value[3403];int dp[12881];int main(){ int N,M; int i,j; scanf("%d*c",&N); scanf("%d*c",&M); memset(weight,0,sizeof(weight)); memset(value,0,sizeof(value)); memset(dp,0,sizeof(dp)); for(i=1; i<=N; i++) { scanf("%d %d*c",&weight[i],&value[i]); } for(i=1; i<=N; i++) { for(j=M; j>=weight[i]; j--) { dp[j] = dp[j-weight[i]] + value[i] > dp[j] ? dp[j-weight[i]] + value[i] : dp[j]; } } printf("%d\n",dp[M]); return 0;}
5. 性能
Ver 1.0 2017-9-18
阅读全文
0 0
- poj 3624&poj 1384
- poj 3624
- POJ 3624
- POJ--3624
- POJ 3624
- poj 3624
- 【POJ】 【3624】
- 【POJ】【3624】
- poj 3624
- poj 3624
- poj 3624
- Poj 3624
- POJ 3624
- poj 3624
- poj 3624 Charm Bracelet
- poj 3624 Charm Bracelet
- poj 3624 Charm Bracelet
- poj 3624 Charm Bracelet
- Numpy 使用教程 3
- 儿歌点点 换歌不算题 旧版 历史版本
- java中的static
- a menu program
- 欢迎使用CSDN-markdown编辑器
- poj 3624
- LCS问题不全汇总
- Numpy 使用教程 4
- Nginx作为七层负载均衡调度器
- NKOJ-3775 数列操作
- 【学习笔记八】- JS 冒泡与捕获(事件流+事件处理程序+事件对象)
- mybatis入门dao方式写URUD(二)
- 数据结构:堆(heap)
- iOS UITableView~delegate(代理方法)