ZOJ 1530 题解

    题目链接:http://acm.zju.edu.cn/show_problem.php?pid=1530

    每次看到special judge总有点怕怕的。不过这个dfs的题目还是不难的。

   题目的意思是这样的,给出一个数n,要输出一个数,这个数能乘除n,并且这个数只有0和1,这个数最长是100位。

    想法就是直接dfs,每次的选择只有0和1,从高位开始搜。

    代码in C++


ExpandedBlockStart.gif 代码
 1  #include < iostream >
 2  using   namespace  std;
 3 
 4  int  notfound ;
 5  void  search( int  a[] , int  len ,  int  rem ,  int  n)
 6  {
 7  if (rem  ==   0   &&  notfound)
 8  {
 9     notfound  =   0  ;
10      for ( int  i  =   0  ; i  <  len ; i  ++ )
11      cout << a[i] ;
12     cout << endl ;
13      return  ;
14  }
15  else   if (notfound  &&  len  <   100 )
16  {
17    
18     a[len]  =   0  ;
19     search(a,len  +   1  , ( 10   *  rem)  %  n , n) ;
20     a[len]  =   1  ;
21     search(a,len  +   1  , ( 10   *  rem  +   1 %  n , n) ;
22  }
23  }
24 
25  int  main()
26  {
27  int  n;
28  int  a[ 100 ] ;
29  while (cin >> &&  n  !=   0 )
30  {
31     a[ 0 =   1  ;
32     notfound  =   1 ;
33     search(a, 1 1 , n) ;
34  }
35 
36  return   0 ;
37  }


转载于:https://www.cnblogs.com/vivyli/archive/2010/02/05/1664071.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值