CF-14E - Camels(DP)是什么型号的骆驼无人机?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1031个文字,预计阅读时间需要5分钟。
Bob喜欢E+-+Camels+Crawling+in+process...Crawling+failedTime+Limit%3A2000MS+Memory+Limit%3A65536KB+64bit+IO+Format%3A%25I64d+%25I64u+Submit+Status+Practice+CodeForces+14E+Description+Bob+likes这样的内容。以下是对这段内容的简化版本:
Bob喜欢:- E+-+Camels+Crawling+in+process...- Crawling+failed- 时间限制:2000MS- 内存限制:65536KB- 64位IO格式:%I64d +%I64u- 提交- 状态- 练习- CodeForces 14E- 描述:Bob喜欢
E - Camels
Crawling in process...Crawling failedTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 14E
Description
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 t humps, representing them as polylines in the plane. Each polyline consists of n vertices with coordinates (x1, y1), (x2, y2), ..., (xn, yn). The first vertex has a coordinate x1 = 1, the second — x2 = 2, etc. Coordinates yi
- there should be t humps precisely, i.e. such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 < yj > yj + 1,
- there should be precisely t - 1 such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 > yj < yj + 1,
- no segment of a polyline should be parallel to the Ox-axis,
- all yi
For a series of his drawings of camels with t 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 t humps for a given number n.
Input
The first line contains a pair of integers n and t (3 ≤ n ≤ 20, 1 ≤ t ≤ 10).
Output
Output the required amount of camels with t
Sample Input
Input
6 1
Output
6
Input
4 2
Output
0
Sample Output
Hint
In the first sample test sequences of y-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of yi).
思路:四维DP,d[n][t][j][s] n代表点数(步长),t代表尖峰数,j代表高度,s代表上升(0)还是下降(1)。
E(dp[1][1][j][0])=1,用上升峰代表完成一个尖峰。初始值看做一个上升峰。
初始值看成上升峰,那么步长为2就会出现下降峰,但这是不合法的,把它都置0就OK了。
f[n][t][i][0]+=f[n-1][t-1][j][1]+f[n-1][t][j][0];///更新上升峰(1:上升峰再加一个上升,2:下降峰加个上升)
f[n][t][i][1]+=f[n-1][t][j][1]+f[n-1][t][j][0];///更新下降峰(1:下降峰再加一个下降,2:上升峰加个下降)
失误:比赛的时候想过用DP,但觉得搜索+减枝也行,就直接搜了,后来才发现搜索会爆。。。
#include<iostream>#include<cstring>using namespace std;const int mm=22;int f[mm][mm][mm][2];int main(){ memset(f,0,sizeof(f)); for(int i=1;i<5;i++) f[1][1][i][0]=1;///边界上升尖峰为1 ///0代表上升,1下降,上升时尖峰减1 for(int k=2;k<=20;k++) for(int l=1;l<=10;l++) for(int i=1;i<=4;i++) { for(int j=1;j<i;j++)///更新上升峰(1:上升峰再加一个上升,2:下降峰加个上升) f[k][l][i][0]+=f[k-1][l-1][j][1]+f[k-1][l][j][0]; if(k==2)f[k][l][i][1]=0;///2步不可能的情况 else for(int j=i+1;j<5;j++)///更新下降峰(1:下降峰再加一个下降,2:上升峰加个下降) f[k][l][i][1]+=f[k-1][l][j][1]+f[k-1][l][j][0]; } int n,t; int ans; while(cin>>n>>t) { ans=0; for(int i=1;i<=4;i++) ans+=f[n][t][i][1]; cout<<ans<<"\n"; }}
本文共计1031个文字,预计阅读时间需要5分钟。
Bob喜欢E+-+Camels+Crawling+in+process...Crawling+failedTime+Limit%3A2000MS+Memory+Limit%3A65536KB+64bit+IO+Format%3A%25I64d+%25I64u+Submit+Status+Practice+CodeForces+14E+Description+Bob+likes这样的内容。以下是对这段内容的简化版本:
Bob喜欢:- E+-+Camels+Crawling+in+process...- Crawling+failed- 时间限制:2000MS- 内存限制:65536KB- 64位IO格式:%I64d +%I64u- 提交- 状态- 练习- CodeForces 14E- 描述:Bob喜欢
E - Camels
Crawling in process...Crawling failedTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 14E
Description
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 t humps, representing them as polylines in the plane. Each polyline consists of n vertices with coordinates (x1, y1), (x2, y2), ..., (xn, yn). The first vertex has a coordinate x1 = 1, the second — x2 = 2, etc. Coordinates yi
- there should be t humps precisely, i.e. such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 < yj > yj + 1,
- there should be precisely t - 1 such indexes j (2 ≤ j ≤ n - 1), so that yj - 1 > yj < yj + 1,
- no segment of a polyline should be parallel to the Ox-axis,
- all yi
For a series of his drawings of camels with t 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 t humps for a given number n.
Input
The first line contains a pair of integers n and t (3 ≤ n ≤ 20, 1 ≤ t ≤ 10).
Output
Output the required amount of camels with t
Sample Input
Input
6 1
Output
6
Input
4 2
Output
0
Sample Output
Hint
In the first sample test sequences of y-coordinates for six camels are: 123421, 123431, 123432, 124321, 134321 и 234321 (each digit corresponds to one value of yi).
思路:四维DP,d[n][t][j][s] n代表点数(步长),t代表尖峰数,j代表高度,s代表上升(0)还是下降(1)。
E(dp[1][1][j][0])=1,用上升峰代表完成一个尖峰。初始值看做一个上升峰。
初始值看成上升峰,那么步长为2就会出现下降峰,但这是不合法的,把它都置0就OK了。
f[n][t][i][0]+=f[n-1][t-1][j][1]+f[n-1][t][j][0];///更新上升峰(1:上升峰再加一个上升,2:下降峰加个上升)
f[n][t][i][1]+=f[n-1][t][j][1]+f[n-1][t][j][0];///更新下降峰(1:下降峰再加一个下降,2:上升峰加个下降)
失误:比赛的时候想过用DP,但觉得搜索+减枝也行,就直接搜了,后来才发现搜索会爆。。。
#include<iostream>#include<cstring>using namespace std;const int mm=22;int f[mm][mm][mm][2];int main(){ memset(f,0,sizeof(f)); for(int i=1;i<5;i++) f[1][1][i][0]=1;///边界上升尖峰为1 ///0代表上升,1下降,上升时尖峰减1 for(int k=2;k<=20;k++) for(int l=1;l<=10;l++) for(int i=1;i<=4;i++) { for(int j=1;j<i;j++)///更新上升峰(1:上升峰再加一个上升,2:下降峰加个上升) f[k][l][i][0]+=f[k-1][l-1][j][1]+f[k-1][l][j][0]; if(k==2)f[k][l][i][1]=0;///2步不可能的情况 else for(int j=i+1;j<5;j++)///更新下降峰(1:下降峰再加一个下降,2:上升峰加个下降) f[k][l][i][1]+=f[k-1][l][j][1]+f[k-1][l][j][0]; } int n,t; int ans; while(cin>>n>>t) { ans=0; for(int i=1;i<=4;i++) ans+=f[n][t][i][1]; cout<<ans<<"\n"; }}

