提交时间:2023-05-23 21:52:04
运行 ID: 74426
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int now,anslen=0x7fffffff,ans[101],sum[10]; bool anspre; struct node{ int num,cost,cnt; } q[10]; void dfs(int len,int res){ if(len>anslen) return; if(res==0){ bool flag=0; if(anslen>len) flag=1; if(q[6].cnt==len) return; anslen=len; int lennow=0,ansnow[101]; for(int i=1;i<=7;i++) sum[i]=q[i].cnt; //for(int i=1;i<=7;i++)cout<<sum[i]<<" "; for(int i=2;i<=7;i++){ if(sum[i]){ lennow=lennow+1; ansnow[lennow]=q[i].num,sum[i]--; break; } } for(int i=1;i<=7;i++) while(sum[i]){ lennow=lennow+1; ansnow[lennow]=q[i].num,sum[i]--; } for(int i=1;i<=lennow;i++){ if(ans[i]>ansnow[i]){ flag=1; break; } } if(!anspre) flag=1; //cout<<anslen<<' ';cout<<endl; if(flag==1){ for(int i=1;i<=anslen;i++) ans[i]=ansnow[i]; anspre=1; } //for(int i=1;i<=anslen;i++)cout<<ansnow[i];cout<<endl; return; } for(int i=1;i<=7;i++){ if(res-q[i].cost>=0){ q[i].cnt++; dfs(len+1,res-q[i].cost); q[i].cnt--; } } } bool cmp(node x,node y){ return x.num<y.num; } int main(){ //freopen("Cola.txt","r",stdin); freopen("stick.in","r",stdin); freopen("stick.out","w",stdout); q[1].num=0,q[1].cost=6; q[2].num=1,q[2].cost=2; q[3].num=2,q[3].cost=5; q[4].num=4,q[4].cost=4; q[5].num=6,q[5].cost=6; q[6].num=7,q[6].cost=3; q[7].num=8,q[7].cost=7; scanf("%d",&now); dfs(0,now); for(int i=1;i<=anslen;i++) printf("%d",ans[i]); printf(" "); if(now%2==1){ int num=(now-3)/2; printf("7"); for(int i=1;i<=num;i++) printf("1"); } else { int num=now/2; for(int i=1;i<=num;i++) printf("1"); } fclose(stdin); fclose(stdout); return 0; }