hdu 1250

滚动数组优化技巧

简单题 没的说

滚动数组

 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

 

转载于:https://www.cnblogs.com/darkdomain/p/4383299.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值