先上代码 b站讲解视频 灯神讲背包 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1010; // 规模 int n, m; // n为件数 m为背包总容量 int f[N][N]; int v[N], w[N]; // 体积v 和 价值w int main() { cin >> n >> m; for…
2017-08-12 18:50:13 writer:pprp 对于最基础的动态规划01背包问题,都花了我好长时间去理解: poj3624是一个最基本的01背包问题: 题意:给你N个物品,给你一个容量为M的背包 给你每个物品的重量,Wi 给你每个物品的价值,Di 求解在该容量下的物品最高价值? 分析: 状态: dp[i][j] = a 剩下i件 当前容量为j的情况下的最大价值为a 如果用 i 来枚举物品编号, 用 j 来枚举重量,那么 if ( j is from 1 to weight[i]…
1068 Find More Coins (30 分) Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special…