/*number is not duplicated*/#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 2600using namespacestd;intN,ANS[MAXN],L,P[MAXN];voidMul (intx) { for(intI=1; i<=l;i++) Ans[i]=ans[i]*x; for(intI=1; i<=l;i++) if(ans[i]>9) {ans[i+1]+=ans[i]/Ten; Ans[i]=ans[i]%Ten; } while(ans[l+1]) {L++; Ans[l+1]+=ans[l]/Ten; ANS[L]=ans[l]%Ten; }}intMain () {scanf ("%d",&N); inti,k,s=0; for(i=2; i;i++) { if(n-i<0) Break; N=n-i;p[++s]=i; } k=N; while(k) for(inti=s;i>=1; i--) if(k) {P[i]++;k--; } ans[1]=1; L=1; for(intI=1; i<=s;i++) Mul (P[i]); for(inti=l;i>=1; i--) printf ("%d", Ans[i]); return 0;}
/*numbers can be duplicated.*/#include<iostream>#include<cstdio>#include<cstring>using namespacestd;intn,ans[100001],l;voidChe (intx) { for(intI=1; i<=l;i++) Ans[i]=ans[i]*x; for(intI=1; i<=l;i++) if(ans[i]>9) {ans[i+1]=ans[i+1]+ans[i]/Ten; Ans[i]=ans[i]%Ten; } if(ans[l+1]>0) l++;}intMain () {CIN>>N; ans[1]=1; L=1; while(n>=5) {n=n-3; Che (3); } Che (n); cout<<l<<Endl; if(l> -) for(inti=l;i>l- -; i--) cout<<Ans[i]; Else for(inti=l;i>=1; i--) cout<<ans[i];}
Codevs 2612 Most decomposition scheme (greedy)