GNY 2015 Running Steps

来源:互联网 发布:ubuntu卸载nvidia驱动 编辑:程序博客网 时间:2024/06/10 01:33

Problem description

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 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.


Sample Input
51 62 83 104 125 60
Sample Output
1 42 13 94 375 40197719157

本题的题意是一个教授训练一群学生走阶梯

其中左脚开始走,每次迈腿可以走一步或者两步

要求走到目标点时满足:

左脚走2步的步数等于右脚走2步的步数,

左脚走1步的步数等于右脚走1步的步数

走2步的次数大于等于走1步的次数

求出所有的方案。

思路是:因为迈2步的步数要大于等于1步的,直接从所有路按两步走开始

然后求1 2的排列组合 然后两步次数减一 一步次数加二继续算

知道走1步次数大于走2步便输出结果

代码如下:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;long long int a[55][55];void init(){    a[0][0]=a[1][0]=a[1][1]=1;    for(int i=2;i<=50;i++){        a[i][0]=1;        for(int j=1;j<=i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j];    }}int main(){    init();    int t;     cin>>t;    while(t--){       int k,n;    cin>>k>>n;       int x=n/2,y=0;       if(x%2){            x--; y+=2;       }       long long int  ans=0;       while(x>=y){            long long int tmp=a[x/2+y/2][y/2];            ans+=(tmp*tmp);            x-=2; y+=4;       }       cout<<k<<" "<<ans<<endl;    }    return 0;}


0 0
原创粉丝点击