HDU-4489-The King’s Ups and Downs

HDU-4489-The King’s Ups and Downs

This question is a combination dp = - = hee hee
Portal

How pinched a coincidence, yesterday I wrote the code to run a combination of probability theory, the results today to the combinations dp, yesterday also plagued with combinatorial problems are forgotten people, happy to fly today ha ha ha

Title probably makes you ask how many waves of sequence = - =
In fact, I do not understand it to the d-what's the use, anyway, I put it after then input the output is gone = - =
rest are pre-play table of. . .
The wave height or a height that is shorter sequence of high order of height, where height is relative.
We consider
an n-th highest personal discharged into n-1 had been properly arranged personal, it is assumed the insertion position is j.
Then the highest left of the first n people are certainly high and low end of
the top of empathy n is some individual right end of the high-low
then we set
dp [i] [0] represents the length of the sequence number i at the beginning of the high-low method
dp [i] [1] indicates the length of the sequence of high and low end i number of methods
taking combinations, as the n-th person has left the individual j-1, nj personal right is
considered to select individuals from n-1 to j-1 personal left, is C (j-1, n-1 )
then the number in this case is to dp [nj] [0] * dp [j - 1] [1] * C (j - 1, n - 1)
Let us think if the position j in the middle of the right, i.e., left the number is equal to the number on the right.
Then the number of methods in this case dp [i] [0] = dp [i] [1]
We use an array ans [i] i Total arranged to meet the requirements of the individual
then the total number of permutations must be symmetric, i.e. the level of the method of the number equal to the low end of the process begins with a high number. Because these arrangements are symmetrical thing.
So there dp [i] [0] = dp [i] [1] = ans [i] / 2;

Well! I explained Wanla ~ ~

~ Code on it

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll dp[25][2];
ll c[25][25];
ll ans[25];

void Combine()
{
	for (int i = 0; i <= 20; i++)
	{
		c[i][0] = 1;
	} 
	for (int i = 1; i <= 20; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
		}
	}
}

void solve()
{
	ans[1] = 1;
	dp[0][0] = dp[0][1] = 1;
	dp[1][0] = dp[1][1] = 1;
	
	for (int i = 2; i <= 20; i++)
	{
		ll cnt = 0;
		for (int k = 0; k <= i; k++)
		{
			int j = i - k - 1;
			cnt += dp[k][0] * dp[j][1] * c[i - 1][j];
		}
		ans[i] = cnt;
		dp[i][0] = dp[i][1] = cnt / 2;
	} 
}

int main()
{
	Combine();
	solve();
	int t;
	cin >> t;
	while (t--)
	{
		ll n, d;
		cin >> d >> n;
		cout << d << " " << ans[n] << endl;
	}
	return 0;
}
发布了39 篇原创文章 · 获赞 2 · 访问量 999

Guess you like

Origin blog.csdn.net/qq_44624316/article/details/104616101