반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> #include <algorithm> #define rep(i,n) for(int i=1;i<=n;i++) using namespace std; int n, arr[1001], dp[1001]; int main() { cin >> n; rep(i, n) { cin >> arr[i]; dp[i] = arr[i]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= i / 2; j++) { dp[i] = max(dp[i], arr[j] + dp[i - j]); } } cout << dp[n]; } | cs |
반응형