CF14E Camels

题目

题目描述
Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he’s drawing camels with tt humps, representing them as polylines in the plane. Each polyline consists of nn vertices with coordinates (x_{1},y_{1})(x
1

,y
1

) , (x_{2},y_{2})(x
2

,y
2

) , …, (x_{n},y_{n})(x
n

,y
n

) . The first vertex has a coordinate x_{1}=1x
1

=1 , the second — x_{2}=2x
2

=2 , etc. Coordinates y_{i}y
i

might be any, but should satisfy the following conditions:

there should be tt humps precisely, i.e. such indexes jj ( 2<=j<=n-12<=j<=n−1 ), so that y_{j-1}<y_{j}>y_{j+1} ,
there should be precisely t-1t−1 such indexes jj ( 2<=j<=n-12<=j<=n−1 ), so that y_{j-1}>y_{j}<y_{j+1} ,
no segment of a polyline should be parallel to the OxOx -axis,
all y_{i}y
i

are integers between 1 and 4.
For a series of his drawings of camels with tt humps Bob wants to buy a notebook, but he doesn’t know how many pages he will need. Output the amount of different polylines that can be drawn to represent camels with tt humps for a given number nn .

输入格式
The first line contains a pair of integers nn and tt ( 3<=n<=203<=n<=20 , 1<=t<=101<=t<=10 ).

输出格式
Output the required amount of camels with tt humps.

题意翻译
题意简述
一行有n个空位,每个空位可以填[1,4][1,4]的整数,相邻两个数不相同,要求:

1.有tt个位置满足 a_{i-1}a
i−1

< a_ia
i

a_{i+1}a
i+1

并且(11<ii<nn)
2.有tt−11个位置满足a_{i-1}a
i−1

a_ia
i

<a_{i+1}a
i+1

输入
第一行: nn 和 tt

输出
第一行:即一共有多少种可能。

数据范围
1≤n≤20, 1≤t≤10

输入输出样例
输入 #1复制
6 1
输出 #1复制
6
输入 #2复制
4 2
输出 #2复制
0
说明/提示
In the first sample test sequences of yy -coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of y_{i}y
i

).

思路

设f[i][j][k][a1][a2]表示第 i位,a[i]=j,a[i-1]=k,已经满足a1个要求1,a2个要求2。
转移详见代码

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std; 
ll n,t,f[25][5][5][25][25]; 
int main()
{
	cin>>n>>t; 
	if(n<=2)
	{
		cout<<"0"; 
		return 0; 
	}
	for(int i=1; i<=4; i++) for(int j=1; j<=4; j++) if(i!=j) f[2][i][j][0][0]=1; 
	for(int l=2; l<=n; l++) for(int a1=0; a1<=t; a1++) for(int a2=0; a2<=t-1; a2++) for(int i=1; i<=4; i++) for(int j=1; j<=4; j++) for(int k=1; k<=4; k++)
	{
		if(i<j&&j>k) f[l+1][j][k][a1+1][a2]+=f[l][i][j][a1][a2]; 
		else if(i>j&&j<k) f[l+1][j][k][a1][a2+1]+=f[l][i][j][a1][a2]; 
		else if(i!=j&&j!=k) f[l+1][j][k][a1][a2]+=f[l][i][j][a1][a2]; 
	}
	ll ans=0; 
	for(int i=1; i<=4; i++) for(int j=1; j<=4; j++) if(i!=j) ans+=f[n][i][j][t][t-1]; 
	cout<<ans;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值