2 条题解
-
2
Leo-S LV 5 @ 3 年前
-
12 年前@
- 1
信息
- ID
- 1096
- 难度
- 2
- 分类
- (无)
- 标签
- 递交数
- 104
- 已通过
- 59
- 通过率
- 57%
- 上传者
#include<bits/stdc++.h>
using namespace std;
int ways(int x);
int main()
{
int x;
cin>>x;
cout<<ways(x)<<endl;
return 0;
}
int ways(int x)
{
if(x==1)
return 1;
else
{
if(x==2)
return 2;
else
{
if(x==3)
return 4;
else
return ways(x-1)+ways(x-2)+ways(x-3);
}
}
}
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int n,k,x,a[30000],b1=1,c1=1,s=4;
int main()
{
a[0]=1,a[1]=1,a[2]=2;
cin>>n;
if(n==1)
cout<<1;
if(n==2)
cout<<2;
if(n>2)
for(int i=3;i<=n;i++)
{
for(int j=i-3;j<i;j++)
a[i]+=a[j];
}
cout<<a[n];
return 0;
}