题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602
这题是非常标准的01背包,没啥特殊的地方,很简单
代码:
#include <bits/stdc++.h> #define MAXS 1006 using namespace std; int value[MAXS]; int main () { int T; int n,m_v,v; int f[MAXS] ; cin >> T; while(T--) { memset(f,0,sizeof(f)); scanf ("%d%d",&n,&m_v); for (int i=0;i<n;++i) scanf("%d",&value[i]); for (int i = 0;i<n;++i) { scanf("%d",&v); for (int j = m_v; j>= v;--j) f[j] = max (f[j],f[j-v] + value[i]); } printf("%d\n", f[m_v]); } return 0; }
原文地址:https://www.cnblogs.com/yuluoluo/p/8900805.html
时间: 2024-10-10 17:45:31