Advertisement
IlidanBabyRage

112616.cpp

Aug 29th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.    
  9.     int n;
  10.     cin >> n;
  11.     int a[1001];
  12.     int m[3] = {1, 5, 6};
  13.     a[0] = 0;
  14.     for (int i = 1; i <= n; i++){
  15.         a[i] = 1001;
  16.         for (int j = 0; j < 3; j++){
  17.             if (i >= m[j])
  18.                 if (a[i - m[j]] + 1 < a[i])
  19.                     a[i] = a[i - m[j]] + 1;
  20.         }
  21.     }
  22.  
  23.     cout << a[n] << endl;
  24.     int t = n;
  25.     int ans[7] = {};
  26.     for (int i = 0; i < a[n]; i++){
  27.         for (int j = 0; j < 3; j++)
  28.             if (t >= m[j] && a[t - m[j]] == a[t] - 1){
  29.                 ans[m[j]]++;
  30.                 t -= m[j];
  31.                 break;
  32.             }
  33.     }
  34.     for (int i = 2; i > -1; i--)
  35.         for (int j = 0; j < ans[m[i]]; j++)
  36.             cout << m[i] << " ";
  37.     cout << endl;
  38.  
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement