求助大佬为何最后一点TLE了,求助大佬

P1149 [NOIP2008 提高组] 火柴棒等式

@[ljx52lm](/user/853953) ```dfs```过不了吧。。。 ```cpp #include<iostream> using namespace std; int a[2010] = {6},c[10]={6,2,5,5,4,5,6,3,7,6}; int main() { int s = 0,l; scanf("%d",&l); for(int i = 1;i <= 2000;i++) { int j = i; while(j >= 1) { a[i] = a[i] + c[j % 10]; j = j / 10; } } for(int i = 0;i <= 1000;i++) for(int j = 0;j <= 1000;j++) if((a[i] + a[j] + a[i + j] + 4) == l) s++; printf("%d\n",s); return 0; } ``` ``求关``**求关**~~求关~~_求关_
by codejiahui @ 2023-03-27 19:23:05


@[codejiahui](/user/512407) 就是tle最后一个点,哎,以为能有剪枝优化啥的
by ljx_gkx @ 2023-03-27 20:15:23


```cpp #include<stdio.h> int main() { int a[2001]={6},b,c[10]={6,2,5,5,4,5,6,3,7,6},s=0,i,j; scanf("%d",&b); for(i=1;i<=2000;i++) { j=i; while(j>=1)//求每个数所用的火柴棒 { a[i]=a[i]+c[j%10]; j=j/10; } } for(i=0;i<=1000;i++) { for(j=0;j<=1000;j++) if(a[i]+a[j]+a[i+j]+4==b)s++;//还有加号与等号 } printf("%d",s); return 0; }
by lienze2012 @ 2023-04-02 21:42:55


```cpp 求关注(我好像来晚了)
by lienze2012 @ 2023-04-02 21:44:15


@[codejiahui](/user/512407) 不懂就问:a[2010]={6} 是什么意思啊
by cxzhyf @ 2023-05-16 13:08:49


@[cxzhyf](/user/523553) 就是等同于`a[2010] = {6,0,0,0,...,0}`
by codejiahui @ 2023-05-16 18:35:17


@[lienze2012](/user/921677) 6复制题解
by Max6700 @ 2023-05-18 21:05:31


|