预处理显然比递归好些…… 郁闷的是,再一次忘了删除中间的结果了,导致一wa 话说我最近怎么总是做水题啊…… #include <iostream> #include <cmath> using namespace std; int main() { int p,t,n,a[5000],i,j; t=1; a[t]=1; p=0; for (i=1;i<=12;i++) { n=t; for (j=1;j<=t;j++) a[++n]=a[j]+int(2*pow(3.0,p*1.0)); p++; t=n; } while (cin >> n) { t=1; for (i=1;i<=int(pow(3.0,n*1.0));i++) if (a[t]==i) { t++; cout << "-"; } else cout << " "; cout << endl; } system("pause"); return 0; }