【链接】
bzoj1081
【解题报告】
找规律。
给个大样例
0000
1000
2000
2100
1100
0100
0200
1200
2200
2210
1210
0210
0110
1110
2110
2010
1010
0010
0020
1020
2020
2120
1120
0120
0220
1220
2220
2221
1221
0221
0121
1121
2121
2021
1021
0021
0011
1011
2011
2111
1111
0111
0211
1211
2211
2201
1201
0201
0101
1101
2101
2001
1001
0001
0002
1002
2002
2102
1102
0102
0202
1202
2202
2212
1212
0212
0112
1112
2112
2012
1012
0012
0022
1022
2022
2122
1122
0122
0222
1222
2222
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=25;
int n,m,a[maxn];
void Dfs(int x,int w)
{
if (x>n) {for (int i=n; i; i--) if (a[i]<10) putchar(a[i]+48); else putchar(a[i]+55); putchar(10); return;}
if (w==0) for (int i=0; i<m; i++) {a[x]=i; if (i%2==0) Dfs(x+1,0); else Dfs(x+1,1);}
else for (int i=m-1; i>=0; i--) {a[x]=i; if (i%2==0) Dfs(x+1,1); else Dfs(x+1,0);}
}
int main()
{
freopen("1081.in","r",stdin);
freopen("1081.out","w",stdout);
scanf("%d%d",&n,&m);
Dfs(1,0);
return 0;
}