Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
想也没想就bfs,MLE,再想得到动规方程f[i][j][k].v表示前i位中余数是j的末尾是k的串有没有 f[i][j][k].x表示前i位中余数是j的末尾是k的串是由长度是i-1的串的余数是什么 f[i][j][k].y表示前i位中余数是j的末尾是k的串是由长度是i-1的串的末尾是什么 cin>>n; f[1][1%n][1].v=1; flag=0; for(int i=1;;i++) { for(int j=0;j<n;j++) { for(int k=0;k<2;k++) if(f[i][j][k].v) { if(j==0) { out(i,j,k);//递归输出 printf("\n"); flag=1; break; } f[i+1][j*10%n][0].v=1; f[i+1][j*10%n][0].x=j; f[i+1][j*10%n][0].y=k; f[i+1][(j*10+1)%n][1].v=1; f[i+1][(j*10+1)%n][1].x=j; f[i+1][(j*10+1)%n][1].y=k; } if(flag)break; } if(flag)break; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator