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 ll=long long; using namespace std; int n; int zuma[555]; int dp[555][555]; int rec(int i, int j) { if(i == j) { return 1; } if(i > j) { return 0; } if(dp[i][j] != -1) { return dp[i][j]; } int result = 2e9; result = min(result, rec(i + 1, j) + 1); if(zuma[i] == zuma[i + 1]) { result = min(result, rec(i + 2, j) + 1); } for(int k = i + 2; k <= j; k++) { if(zuma[i] == zuma[k]) { result = min(result, rec(i + 1, k - 1) + rec(k + 1, j)); } } return dp[i][j] = result; } int main() { cin >> n; for(int i = 0; i < n; i++){ cin >> zuma[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)