题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602
裸的。。。
1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <climits> 6 #include <complex> 7 #include <fstream> 8 #include <cassert> 9 #include <cstdio> 10 #include <bitset> 11 #include <vector> 12 #include <deque> 13 #include <queue> 14 #include <stack> 15 #include <ctime> 16 #include <set> 17 #include <map> 18 #include <cmath> 19 20 using namespace std; 21 22 const int maxn = 555555; 23 int n, m; 24 int v[maxn]; 25 int w[maxn]; 26 int dp[maxn]; 27 28 int main() { 29 // freopen("in", "r", stdin); 30 int T; 31 scanf("%d", &T); 32 while(T--) { 33 memset(dp, 0, sizeof(dp)); 34 memset(v, 0, sizeof(v)); 35 memset(w, 0, sizeof(w)); 36 scanf("%d %d", &n, &m); 37 for(int i = 1; i <= n; i++) scanf("%d", &v[i]); 38 for(int i = 1; i <= n; i++) scanf("%d", &w[i]); 39 for(int i = 1; i <= n; i++) { 40 for(int j = m; j >= w[i]; j--) { 41 dp[j] = max(dp[j], dp[j-w[i]]+v[i]); 42 } 43 } 44 printf("%d\n", dp[m]); 45 } 46 return 0; 47 }
时间: 2024-11-05 00:42:21