Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created December 31, 2013 05:24
Show Gist options
  • Select an option

  • Save KT-Yeh/8192950 to your computer and use it in GitHub Desktop.

Select an option

Save KT-Yeh/8192950 to your computer and use it in GitHub Desktop.
#include <cstdio>
using namespace std;
int main()
{
int ans[77];
ans[1]=1;
ans[2]=2;
ans[3]=2;
for(int i=4;i<=76;i++)
ans[i]=ans[i-2]+ans[i-3];
int n;
while(scanf("%d",&n)!=EOF)
printf("%d\n",ans[n]);
return 0;
}
//*********遞迴版**********
#include <cstdio>
using namespace std;
void graph(int n,int i);
int numOfSub;
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
numOfSub=0;
for(int i=1;i<=2&&i<=n;i++)
graph(n,i);
printf("%d\n\n",numOfSub);
}
return 0;
}
void graph(int n,int i)
{
if(i+2>=n){
numOfSub++;
return;
}
graph(n,i+2);
graph(n,i+3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment