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
using namespace std; typedef long long ll; const int maxn = 505; ll potions[maxn]; ll dp[maxn][maxn]; ll sum(int i, int j) { ll result = 0; for(int k = i; k <= j; k++) { result += potions[k]; } return result % 100; } ll rec(int i, int j) { if(i + 1 == j) { return potions[i] * potions[j]; } if(i >= j) { return 0; } if(dp[i][j] != -1) { return dp[i][j]; } ll result = 2e15; for(int k = i; k < j; k++) { result = min(result, rec(i, k) + rec(k + 1, j) + sum(i, k) * sum(k + 1, j)); } return dp[i][j] = result; } int main() { ios_base::sync_with_stdio(false); int n; while(cin >> n) { for(int i = 0; i < n; i++) { cin >> potions[i]; } memset(dp, -1, sizeof dp); cout << rec(0, n - 1) << 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)