Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
- using namespace std;
- int arr[] = {0, 13,8,11,7,9,17,12,14,19,15,16,15,15,13,14 };
- int n = 15;
- int dp[17] = {};
- int trac[17] = {};
- int main() {
- fastio;
- {dp[1] = arr[1]; dp[2] = arr[2]; dp[3] = arr[3]; }
- trac[1] = trac[2] = trac[3] = -1;
- for(int i=4;i<=n;i++){
- dp[i] = dp[i - 3];
- trac[i] = i - 3;
- if (dp[i] > dp[i - 2]) {
- dp[i] = dp[i - 2];
- trac[i] = i - 2;
- }
- if (dp[i] > dp[i - 1]) {
- dp[i] = i - 1;
- trac[i] = i - 1;
- }
- dp[i] += arr[i];
- }
- vector<int> v;
- int idx = n;
- while (1) {
- if (trac[idx] == -1) break;
- v.push_back(trac[idx]);
- idx = trac[idx];
- }
- reverse(v.begin(), v.end());
- for (int i : v) cout << i << " ";
- cout << n << "\n";
- cout << dp[n];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement