fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. void dfs(int k,int sz);
  5. bool f(int n);
  6. int N;
  7. int main(){
  8. cout.tie(NULL);
  9. cin.tie(NULL);
  10. ios_base::sync_with_stdio(false);
  11. cin>>N;
  12. dfs(0,0);
  13. }
  14. void dfs(int k,int sz){
  15. if(sz==N)
  16. {
  17. if(f(k)==true)
  18. {
  19. cout<<k<<"\n";
  20. return;
  21. }
  22. else
  23. {
  24. while(f(k)!=true)
  25. {
  26. k++;
  27. }
  28. cout<<k<<"\n";
  29. return;
  30. }
  31. }
  32. while(1)
  33. {
  34. if(f(k)==true)//n이 감소수라면
  35. {
  36. dfs(1+k,1+sz);
  37. return;
  38. }
  39. else
  40. {
  41. k++;
  42. }
  43. }
  44. }
  45. bool f(int n){
  46. int a=-1;
  47. while(n>0)
  48. {
  49. if(n%10<=a)
  50. {
  51. return false;
  52. }
  53. a=n%10;
  54. n=n/10;
  55. }
  56. return true;
  57. }
Success #stdin #stdout 0.44s 5540KB
stdin
1000
stdout
98764320