拼图
拼图
Time Limit: 1000MS | Memory Limit: 65535KB |
Submissions: 117 | Accepted: 69 |
Sample Input
3 4
Sample Output
5 11
#include <iostream> #include <stdio.h> using namespace std; int n,num; int b[3]={1,2,2}; void dfs(int index) { int i; if(index>n) { return ; } if(index==n) { num++; } for(i=0;i<3;i++) { dfs(index+b[i]); } } int main() { while(scanf("%d",&n)!=EOF) { num = 0; dfs(0); printf("%d\n",num); } return 0; }
规律
# include<stdio.h> int f(int n) { if(n==1)return 1; if(n==2)return 3; return 2*f(n-2)+f(n-1); } int main() { int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",f(n)); } return 0; }