人生列车

follow on!success!

导航

组合数打表法(1587: 爬楼梯)

这道题思路比较清晰,采用的方法是组合数打表法:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1587

(1587: 爬楼梯)

#include <iostream>
#define max 46
using namespace std;

long long c[max][max];
int main()
{
    for(int i = 0;i < max;i++){
        c[i][0]=1;
        c[i][i]=1;
    }
    for(int i = 1;i < max;i++){
        for(int j = 1;j < i;j++){
            c[i][j]=c[i-1][j] + c[i-1][j-1];
        }
    }
    /*
    for(int i = 0;i < max;i++){
        for(int j = 0;j < max;j++){
            cout<<c[i][j]<<" ";
        }
        cout<<endl;
    }
    */
    int t,z;
    cin>>t;
    while(t--){
        cin>>z;
        int m = z/2;
        long long count=0;
        //这个相当于一个排列组合的问题
        for(int i = 0;i <= m;i++)
        {
            count+=c[z-i][i];
        }
        cout<<count<<endl;

    }
    return 0;
}

 

posted on 2015-05-02 16:28  tianxia2s  阅读(464)  评论(0编辑  收藏  举报