首页 > 学院 > 开发设计 > 正文

【Uestc 1423 Running Steps】+ 排列组合

2019-11-06 08:03:04
字体:
来源:转载
供稿:网友

B  Running Steps The coach wants his team members to run up the stadium steps taking either one or two steps with each stride so that: a) The number of two step strides taken by each leg is the same. b) The number of one step strides taken by each leg is the same. c) The number of two step strides is no smaller than the number of one step strides. d) Start with the left leg. The coach wants to know for a given (necessarily even) number of steps how many different ways there are to run the steps and satisfy his rules. For example, with six steps (three for each leg), there are 4 possibilities: 2211, 2112, 1221, 1122 (right leg strides are in highlighted type) With eight steps (four for each leg) there is only one possibility since there must be at least as many two step strides as one step strides: 2222 For this PRoblem, you will write a program that calculates the number of different ways there are to run the steps that satisfy the coach’s four criteria. Input The first line of input contains a single integer P, (1  P  10000), which is the number of data sets that follow. Each data set should be processed identically and independently. Each data set consists of a single line of input. It contains the data set number, K, followed by an even integer which is the total number of steps to be run, S, (2  S  100). Output For each data set there is a single line of output. The single output line consists of the data set number, K, followed by a single space followed by the number of different ways of running the steps that satisfy the coach’s four criteria. Greater New York Regional B • Running Steps Sample Input Sample Output 5 1 6 2 8 3 10 4 12 5 60 1 4 2 1 3 9 4 37 5 40197719157

一条腿1 和 2 的排列组合 * 另一条腿的排列组合? 排列组合也可以用dp来记录

AC代码:

#include<cstdio>#define f(i,a,b) for(int i = a; i <= b; i++)typedef long long LL;LL dp[51][51]; // 排列组合void init(){ dp[1][1] = 1; f(i,1,50) dp[i][0] = 1; f(i,2,50) f(j,1,i) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];}int main(){ int T,N,K; init(); scanf("%d",&T); while(T--){ scanf("%d %d",&K,&N); int n1 = 0,n2 = N / 2; if(n2 % 2) n2 --,n1 += 2; LL ans = 0,cut; while(n1 <= n2) cut = dp[(n1 + n2) / 2][n2 / 2], ans += cut * cut , n2 -= 2, n1 += 4; printf("%d %lld/n",K,ans); } return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表