And a few days ago in the school of a NOIP simulation T3 exactly the same ...
DP (I,J) indicates the number of legitimate schemes that start with 1~j and begin with a descent in the 1~i arrangement
This sequence is symmetric, that is, for an arrangement {an} that satisfies test instructions and begins with ascending n, so that bn = N-an+1, then {bn} is a sequence that satisfies test instructions and begins with a descent
DP (I,J) = DP (I,J-1) + DP (i-1,i-j+1). Before a good understanding, is to arrange I, 1~j-1 beginning, the latter is to ask to start with J, then the original arrangement i-1 should start with the 1~j-1, but the beginning of the rise (this will be in line with the J test instructions), so is DP (I-1, (i-1)-(j-1) +1)
The final answer is * (counting up the beginning), using a scrolling array. Time complexity O (N2), Space complexity O (N)
--------------------------------------------------------------------------
#include <bits/stdc++.h> using namespace std;const int MAXN = 4209;int N, MOD, DP[2][MAXN];int main () {scanf ("%d%d", &n, &mod);memset (DP, 0, sizeof DP);int c = 0, p = 1;dp[c][1] = 1;for (int i = 2; I <= N; i++) {Swap (c, p);memset (Dp[c], 0, sizeof dp[c]);For (int j = 1; J <= I; j + +) {Dp[c][j] = dp[c][j-1] + dp[p][i-j + 1];if (Dp[c][j] >= MOD)Dp[c][j]-= MOD;}}int ans = 0;for (int i = 1; I <= N; i++)if (ans + = dp[c][i]) >= mod) ans-= mod;printf ("%d\n", (ans << 1)% MOD);return 0;}
--------------------------------------------------------------------------
1925: [Sdoi2010] Goblin Tribe Time Limit:Ten Sec Memory Limit:MB
Submit:965 Solved:580
[Submit] [Status] [Discuss] Description legend a long time ago, the Earth lived a mysterious creature: Goblin. Goblins like to live in the Endless Mountains. Specifically, an n-length mountain range h can be divided into n segments from left to right, each with a unique height of hi, where hi is a positive integer between 1 and N. If a mountain range is higher than all the mountains adjacent to it, the mountain range is a mountain. The mountains at the edge have only one contiguous mountain range, others have two segments (i.e. left and right). Similarly, if a mountain range is lower than all its adjacent mountains, the mountain range is a valley. Goblins have a common hobby-drinking, pubs can be set up in the valley. The Goblin's Tavern is always noisy during the day and night, and the scent of the fine wine can float to a radius of the place. Goblin is also a very alert creature, they can set up a lookout on each mountain, and take turns as lookout work to ensure that the first time to know the invasion of foreign enemies. The Goblins hope that each section of the N-section of the mountain can be built into one of the observatory or tavern, and only the entire mountain range that satisfies this condition may be inhabited by the goblins. Now you want to know how many kinds of mountain ranges may be inhabited by N in length. Two Mountains A and b are different when and only if there is an I, which makes Ai≠bi. Since this number may be large, you are only interested in dividing it by the remainder of P. Input contains only one row, two positive integers N, P. Output contains only one row, a non-negative integer, indicating the result of the answer you have asked for after P is taken. Sample Input 4 7Sample Output 3HINT
For 20% of data, meet n≤10;
For 40% of data, meet n≤18;
For 70% of data, meet n≤550;
For 100% of data, meet 3≤n≤4200,p≤109
Source
First round Day2
Bzoj 1925: [Sdoi2010] Goblin Tribe (DP)