poj 1426 深搜

***可能有多个答案,DFS一下找出一个答案即可***

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#define N 11000
using namespace std;
typedef long long LL;

int n, f;

void DFS(LL num, int t)
{
    if(t==20 || f)
        return ;
    if(num%n==0&&num!=0)
    {
        printf("%I64d
", num);
        f=1;
    }
    DFS(num*10, t+1);
    DFS(num*10+1, t+1);
}

int main()
{
    while(scanf("%d", &n), n)
    {
        f=0;
        DFS(1, 1);
        //printf("%lld
", ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/9968jie/p/5675342.html