Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- int main(){
- int n;
- cin >> n;
- int a[1001];
- int m[3] = {1, 5, 6};
- a[0] = 0;
- for (int i = 1; i <= n; i++){
- a[i] = 1001;
- for (int j = 0; j < 3; j++){
- if (i >= m[j])
- if (a[i - m[j]] + 1 < a[i])
- a[i] = a[i - m[j]] + 1;
- }
- }
- cout << a[n] << endl;
- int t = n;
- int ans[7] = {};
- for (int i = 0; i < a[n]; i++){
- for (int j = 0; j < 3; j++)
- if (t >= m[j] && a[t - m[j]] == a[t] - 1){
- ans[m[j]]++;
- t -= m[j];
- break;
- }
- }
- for (int i = 2; i > -1; i--)
- for (int j = 0; j < ans[m[i]]; j++)
- cout << m[i] << " ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement