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 width, n; int steps[55]; int dp[55][2002]; int rec(int at, int position) { if(at == n) { return position; } if(dp[at][position] != -1) { return dp[at][position]; } int result = -1; if(position - steps[at] >= 0) { result = max(result, rec(at + 1, position - steps[at])); } if(position + steps[at] <= width) { result = max(result, rec(at + 1, position + steps[at])); } return dp[at][position] = result; } int main() { int S; cin >> S >> width; cin >> n; for(int i = 0; i < n; i++) { cin >> steps[i]; } for(int i = 0; i <= n; i++) { for(int j = 0; j <= 2000; j++) { dp[i][j] = -1; } } cout << rec(0, S) << 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)