01背包
题目链接 https://hihocoder.com/contest/hiho6/problem/1
#include <bits/stdc++.h> using namespace std; const int N = 500 + 10; int need[N], value[N]; int dp[100000+10]; int main () { int n,V; scanf("%d %d", &n, &V); for(int i=1;i<=n;i++) scanf("%d %d", &need[i], &value[i]); for(int i=1;i<=n;i++) { for(int j=V; j>=need[i]; j--) { dp[j] = max(dp[j], dp[j-need[i]] +value[i]); } } cout << dp[V] <<endl; return 0; }