码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-02 18:02:15      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

这道题思路比较清晰,采用的方法是组合数打表法: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;
}

 

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

标签:

原文地址:http://www.cnblogs.com/tianxia2s/p/4472143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!