Created
February 17, 2018 16:15
-
-
Save junodeveloper/a9d8bfc933f80c1701762fe91a776d61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<algorithm> | |
using namespace std; | |
int a[10],c[11][11],n; // c : 조합 | |
int main() { | |
scanf("%d",&n); | |
for(int i=0;i<=10;i++) c[i][0]=c[i][i]=1; | |
for(int i=1;i<=10;i++) for(int j=1;j<i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1]; | |
if(n<1023) { | |
int k=1,s=0; // k : 자릿수, s : k자리 이하의 감소하는 수 개수 | |
for(;k<=9 && s+c[10][k]<=n;s+=c[10][k],k++); | |
for(int i=9;i>9-k;i--) a[i]=1; // k개 1로 바꿈 | |
for(int i=0;i<n-s;i++) next_permutation(a,a+10); | |
for(int i=0;i<10;i++) if(a[i]) printf("%d",9-i); | |
} else printf("-1"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment