1 条题解
-
0
C :
#include<stdio.h> #include<math.h> long stap(long a) { if(a==1) return 0; if(a==2) return 1; if(a==3) return 2; if(a==4) return 2; if(a>4) return stap(a-2)+2*stap(a-3)+stap(a-4); } main() { long a,l; scanf("%d",&a); l=stap(a); printf("%d",l); }
C++ :
#include<iostream> //有左右脚的限制。 using namespace std; const int N=39; int f(int x,int y) { if(x==0||y==0) return 1; return(f(x-1,y)+f(x,y-1));//递归的关键在此,大规模逐渐转化为小规模。 } int main() { int x,y,n,sum=0;//x表示走两步的次数,y表示走一步的次数。 int i,sum=0; cin>>n; x=n/2; for(int i=x;x>=0;x-=2) //为了保持偶数步,必须x每次递减2,而不是1;(x要x>=0,不能x>0),x=0是针对偶数台阶。 { y=n-2*x; sum+=f(x,y); //求组合数; } cout<<sum<<endl; return 0; }
- 1
信息
- ID
- 482
- 时间
- 3000ms
- 内存
- 4MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者