【链接】
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;
}

本文提供了一道编号为BZOJ1081的问题的解题思路及代码实现。通过递归深度优先搜索的方式,按特定顺序遍历所有可能的数,并输出这些数。该算法根据输入的n和m生成一个特定的数字序列。
1260

被折叠的 条评论
为什么被折叠?



