Skip to content

Instantly share code, notes, and snippets.

@mryoshio
Created November 12, 2014 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mryoshio/57d03a27afd95e39cc26 to your computer and use it in GitHub Desktop.
Save mryoshio/57d03a27afd95e39cc26 to your computer and use it in GitHub Desktop.
lod with DP
#include <iostream>
#include <algorithm>
using namespace std;
int prices[] = { 0, 1, 5, 8, 9, 10, 17, 17, 20, 24, 30 };
int N;
void solve() {
for (int i = 1; i <= N; i++) {
int v = 0;
for (int j = 1; j <= i; j++)
v = max(v, prices[j] + prices[i-j]);
prices[i] = v;
}
cout << "lod(" << N << "): " << prices[N] << endl;
}
int main() {
cout << "N: "; cin >> N;
solve();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment