Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
#include
using namespace std; typedef long long ll; const int maxn = 100 + 10; const ll INF = 2e17; int n; int weights[maxn], values[maxn]; ll dp[maxn][100005]; ll rec(int at, int weight_capacity) { if(at >= n) { return 0; } if(dp[at][weight_capacity] != -1) { return dp[at][weight_capacity]; } ll res = -INF; res = max(res, rec(at + 1, weight_capacity)); if(weight_capacity >= weights[at]) { res = max(res, rec(at + 1, weight_capacity - weights[at]) + values[at]); } dp[at][weight_capacity] = res; return res; } int main() { memset(dp, -1, sizeof dp); int W; cin >> n >> W; for(int i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } cout << rec(0, W) << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)