Advertisement
Saleh127

UVA 12955

May 19th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11.  
  12. ll f[20],i,j,k,l;
  13.  
  14. f[0]=f[1]=1;
  15.  
  16. for(i=2; i<=10; i++) f[i]=f[i-1]*i;
  17.  
  18. ll dp[100005];
  19.  
  20. for(i=0;i<=100002;i++) dp[i]=INT_MAX;
  21.  
  22. dp[0]=1;
  23.  
  24. for(i=0; i<=10; i++)
  25. {
  26. for(j=1; j<=100000; j++)
  27. {
  28. if(j>=f[i])
  29. {
  30. dp[j]=min(dp[j],dp[j-f[i]]+1);
  31. }
  32. }
  33. }
  34.  
  35. ll n;
  36.  
  37. while(cin>>n)
  38. {
  39. cout<<dp[n]-1<<endl;
  40. }
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement