骨牌铺方格
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33758 Accepted Submission(s): 16359
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 #include<vector> 6 #include<cstdlib> 7 #include<math.h> 8 using namespace std; 9 const int inf=0x3f3f3f3; 10 const int maxn=57; 11 long long dp[maxn]; 12 long long slove(int n) 13 { 14 dp[1]=1;dp[2]=2; 15 for(int i=3;i<=n;i++) 16 { 17 dp[i]=dp[i-1]+dp[i-2]; 18 } 19 return dp[n]; 20 } 21 int main() 22 { 23 int n; 24 while(~scanf("%d",&n)){ 25 if(n==1){printf("1\n");continue;} 26 if(n==2) {printf("2\n");continue;} 27 long long ans=slove(n); 28 cout<<ans<<endl; 29 } 30 }
原文:http://www.cnblogs.com/codeyuan/p/4358089.html