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
using namespace std; int n; int cost[105], weight[105]; long long dp[101][100001]; long long rek(int att, int cost_left) { if(cost_left == 0) { return 0; } if(att==n) { return 2e9; } if(dp[att][cost_left] != -1) { return dp[att][cost_left]; } long long maks = 1e15; maks = min(maks, rek(att + 1, cost_left)); // sto ako ne go zememe ovoj element if(cost_left - cost[att] >= 0) { maks = min(maks, rek(att + 1, cost_left - cost[att]) + weight[att]); // sto ako go zememe ovoj element } dp[att][cost_left] = maks; return maks; } int main() { cin >> n; int max_weight; cin >> max_weight; for(int i = 0; i < n; i++) { cin >> weight[i] >> cost[i]; } for(int i = 0; i < n; i++) { for(int j = 0; j <= 100000; j++) { dp[i][j] = -1; } } int rez; for(int j = 0; j <= 100000; j++) { if(rek(0,j)<=max_weight) { rez=j; } } cout<
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)