[Blue Bridge Cup] The second simulation (software) real questions of the 11th Blue Bridge Cup Competition_Undergraduate Group

Article Directory

link address

The swing sequence explains the address in detail.
Note that the state of odd and even rows is defined differently, so the final answer will depend on whether it is odd or even! This is great!

​ 下面我们来详细的解释一下dp的过程。
这里我们计算的时候先从第一行开始,为第一行进行一个初始化,初始化为下一行可以选择的值的数目,即当前所能组成的摆动数列的个数。
我们初始化dp[1][i] = n - i + 1;

第一行中,令 d[1][j]为:第1个数选择大于等于 j的数的方案总数。

从第二行开始:

​ 奇数行中,令 d[i][j]为:第i个数选择大于等于j的数时的方案总数。
​ 偶数行中,令 d[i][j]为:第i个数选择小于等于j的数时的方案总数。

即从第二行开始,如果行数为偶数行,那么我们当前可能的数目为:dp[i][j] = (dp[i-1][j+1] + dp[i][j-1]) % 10000;,如果为奇数行则:dp[i][j] = (dp[i-1][j-1] + dp[i][j+1]) % 10000;。

​ 然后这样的话,如果我们总的长度为奇数的话,那么就是dp[m][1],如果是偶数,则为dp[m][n]

Guess you like

Origin blog.csdn.net/weixin_43154149/article/details/108998713