BZOJ1081(SCOI2005)[超级格雷码]--找规律+暴搜

【链接】
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值