diff --git a/00lanqiao chap/test100-1-1.cpp b/00lanqiao chap/test100-1-1.cpp new file mode 100644 index 0000000..0fb0c7e --- /dev/null +++ b/00lanqiao chap/test100-1-1.cpp @@ -0,0 +1,21 @@ +// lanqiao 1174 小明的背包1 +#include +using namespace std; +#define int long long +#define endl '\n' +const int N = 1e2+10, M = 1e3 + 10; +int dp[N][M]; +signed main() +{ + // 请在此输入您的代码 + int n, V; cin >> n >> V; + for(int i = 1; i <= n; i++){ + int w, v; cin >> w >> v; + for(int j = 0; j <= V; j++){ + if(j >= w) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w] + v); + else dp[i][j] = dp[i-1][j]; + } + } + cout << dp[n][V] << endl; + return 0; +} \ No newline at end of file