题解:
先暴力找规律
然后就一加一减的枚举
代码:
#include<bits/stdc++.h> using namespace std; int n,m,f[55],p[55]; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++)f[i]=1,p[i]=0; while (1) { for (int i=1;i<=n;i++) if (p[i]>9)putchar(p[i]-10+'A'); else putchar(p[i]+'0'); puts(""); int i=1; while ((p[i]+f[i]<0||p[i]+f[i]>=m)&&i<=n)i++; p[i]+=f[i]; if (i>n)return 0; for (i-=1;i;i--)f[i]=-f[i]; } }