标签:write spec 规律 turn sample line 先来 table source
Time Limit: 1000MS | Memory Limit: 10000K | |||
Total Submissions: 28550 | Accepted: 11828 | Special Judge |
Description
Input
Output
Sample Input
2 6 19 0
Sample Output
10 100100100100100100 111111111111111111
Source
#include<stdio.h> int n,ans[400]; bool found; void dfs(int mod,int dep) { if(found || dep>19) return; if(mod==0) { for(int i=0;i<=dep;++i) printf("%d",ans[i]); printf("\n"); found=true; return; } ans[dep+1]=1; dfs((mod*10+1)%n,dep+1); //mod的运算规律,可以这样想:假设X为当前位以前所有的数,那么当前数为X*10+i(i=0/1),对其取n的余数,(X%n*10%n+i%n)%n,递推即可。 ans[dep+1]=0; dfs((mod*10)%n,dep+1); } int main() { int i; while(~scanf("%d",&n)) { if(n==0) break; found=false; ans[0]=1; dfs(1%n,0); } return 0; }
[深度优先搜索] POJ 1426 Find The Multiple
标签:write spec 规律 turn sample line 先来 table source
原文地址:http://www.cnblogs.com/fuermowei-sw/p/6215703.html