解题思路:
注意事项:
递归的话时间会超出限制
参考代码:
运行正确代码:
#include<stdio.h>
int main(){
int a[54]={1,2,3,4},n,i;
for(i=4;i<54;i++)
a[i]=a[i-1]+a[i-3];
scanf("%d",&n);
while(n!=0){
printf("%d\n",a[n-1]);
scanf("%d",&n);
}
return 0;
}
#include<stdio.h>
时间超限:
int niu(int n){
if(n<4)
return n;
return niu(n-1)+niu(n-3);
}
int main(){
int n;
scanf("%d",&n);
while(n!=0){
printf("%d\n",niu(n));
scanf("%d",&n);
}
return 0;
}
0.0分
0 人评分
A+B for Input-Output Practice (IV) (C++代码)浏览:677 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:751 |
兰顿蚂蚁 (C++代码)浏览:1045 |
蛇行矩阵 (C语言代码)浏览:535 |
简单的a+b (C语言代码)浏览:579 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:586 |
交换Easy (C语言代码)浏览:761 |
计算质因子 (C语言代码)浏览:707 |
【计算直线的交点数】 (C语言代码)浏览:922 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:1220 |