简单题 没的说

滚动数组

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <queue>
 4 #include <cstring>
 5 #include <cstdio>
 6 #include <vector>
 7 #include <string>
 8 #include <iterator>
 9 #include <cmath>
10 #include <deque>
11 #include <stack>
12 #include <cctype>
13 using namespace std;
14 
15 const int N = 2500;
16 const int INF = 0xfffffff;
17 
18 typedef long long ll;
19 typedef long double ld;
20 
21 #define INFL 0x7fffffffffffffffLL
22 #define met(a, b) memset(a, b, sizeof(a))
23 #define rep(c, a, b) for (int c = a; c < b; c++)
24 #define nre(c, a, b) for (int c = a; c > b; c--)
25 
26 //h(n) = ( (4*n-2) / (n+1) ) * h(n-1);
27 
28 int ans[5][N];
29 
30 int main ()
31 {
32     int n;
33     while (cin >> n)
34     {
35         met (ans, 0);
36         ans[1][0] = ans[2][0] = ans[3][0] = ans[4][0] = 1;
37         rep (i, 5, n+1)
38         {
39             int t = 0, m = i % 5;
40             rep (j, 0, N)
41             {
42                 int x = ans[0][j] + ans[1][j] + ans[2][j] + ans[3][j] + ans[4][j] + t - ans[m][j];
43                 ans[m][j] = x % 10, t = x / 10;
44             }
45         }
46         int len = N - 1;
47         while (ans[n%5][len] == 0) len--;
48         while (len >= 0) cout << ans[n%5][len--];
49         cout << endl;
50     }
51     return 0;
52 }
View Code

 

posted on 2015-04-01 11:02  白夜叉降临  阅读(112)  评论(0编辑  收藏  举报