Poetize11的T3

DP神优化= =反正蒟蒻不会

Orz ZYF竟然找到了题解,反正我是没找到T T(百度空间:你太沙茶了,不给你看题解2333)

然后就对着标程写了一遍,然后T了。。。233

蒟蒻十分愤怒!!!为毛标程T了。。。你倒是告诉我!!!

 

 1 #include <cstdio>
 2 #include <algorithm>
 3 
 4 using namespace std;
 5 typedef long long ll;
 6 const int N = 3000;
 7 const int M = 3005;
 8 const int H = 35;
 9 const ll mod = 1000000000;
10 
11 int n;
12 int maxh[H], minh[H], L[M], R[M];
13 ll dp[M][H], ans[M]; 
14 
15 inline int read() {
16     int x = 0;
17     char ch = getchar();
18     while (ch < '0' || '9' < ch)
19         ch = getchar();
20     while ('0' <= ch && ch <= '9') {
21         x = x * 10 + ch - '0';
22         ch = getchar();
23     }
24     return x;
25 }
26 
27 void pre_work() {
28     int i, j;
29     minh[1] = maxh[1] = 1, minh[2] = 2, maxh[2] = 3;
30     for (i = 3; i <= 30; ++i)
31         minh[i] = minh[i - 1] + minh[i - 2],
32         maxh[i] = maxh[i - 1] << 1 | 1;
33     for (i = 1; i <= 30 && minh[i] <= N; ++i)
34         for (j = minh[i]; j < min(minh[i + 1], N + 1); ++j)
35             R[j] = i;
36     for (L[1] = 1, i = 2; i <= 30 && maxh[i - 1] <= N; ++i)
37         for (j = maxh[i - 1] + 1; j <= min(maxh[i], N); ++j)
38             L[j] = i;
39 }
40 
41 void DP() {
42     int i, j, h, l, r;
43     dp[0][0] = dp[1][1] = 1, ans[1] = 1;
44     for (i = 2; i <= N; ++i){
45         for (l = 0; l < i; ++l)
46             for (r = i - l - 1, h = max(0, L[i] - 2); h <= min(29, R[i] - 1); ++h) {
47                 if (h) dp[i][h + 1] += dp[l][h] * dp[r][h - 1];
48                 (dp[i][h + 1] += dp[l][h] * dp[r][h]) %= mod;
49                 dp[i][h + 2] += dp[l][h] * dp[r][h + 1];
50             }
51         for (h = 1; h <= min(29, i); ++h)
52             ans[i] += dp[i][h];
53         ans[i] %= mod;
54     }
55 }
56 
57 int main() {
58     pre_work();
59     DP();
60     while ((n = read()) != 0)
61         printf(n >= 38 ? "%09lld\n" : "%lld\n", ans[n]);
62     return 0;
63 }
View Code(TLE的标程)

相关文章:

  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
  • 2021-07-28
  • 2021-12-16
  • 2021-11-18
猜你喜欢
  • 2021-10-01
  • 2021-04-06
  • 2021-12-18
  • 2021-12-21
  • 2022-12-23
  • 2022-01-02
  • 2021-06-25
相关资源
相似解决方案