穷举加递归的有关问题[推荐]
穷举加递归的问题[推荐]
构造一个i位数,每位数的选择范围分别是0-A(1),0-A(2).....o-A(i),穷举此i位数
跪求算法
------解决方案--------------------
构造一个i位数,每位数的选择范围分别是0-A(1),0-A(2).....o-A(i),穷举此i位数
跪求算法
------解决方案--------------------
- C/C++ code
#include <stdio.h> #include <stdlib.h> #include <memory.h> #include <string.h> char last_put[100]=""; int arrayList(int n,char *ptrString) { int i,strLens; char tmp[10]; if(n==1) { for(i=0;i<10;i++) { printf("%s",ptrString); printf("%d\n",i); } return 0; } for(i=0;i<10;i++) { //printf("%d",i); sprintf(tmp,"%d",i); strLens = strlen(ptrString); strcat(ptrString,tmp); arrayList(n-1,ptrString); ptrString[strLens] = '\0'; } return 0; } void main() { arrayList(5,last_put); getchar(); }