Problem C: 爬楼梯

传送门:http://gdutcode.sinaapp.com/problem.php?cid=1056&pid=2

实现代码:

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const long long  MOD=10007;

long long a[30];

void init(){
    a[0]=0;
    a[1]=1;
    a[2]=2;
    a[3]=4;
    for(int i=4;i<30;i++)
        a[i]=a[i-1]+a[i-2]+a[i-3];
}

int main(){
    int T;
    scanf("%d",&T);
    init();
    while(T--){
        long long ans=1;
        int n;
        scanf("%d",&n);
        for(int i=1;i<n;i++){
            int tmp;
            scanf("%d",&tmp);
            ans*=a[tmp];
            ans%=MOD;
        }
        cout<<ans<<endl;
    }
    return 0;
}

/**************************************************************
    Problem: 1226
    User: MKF
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1696 kb
****************************************************************/
时间: 2024-08-09 22:00:01

Problem C: 爬楼梯的相关文章

组合数打表法(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

LeetCode | 0070. Climbing Stairs爬楼梯【Python】

LeetCode 0070. Climbing Stairs爬楼梯[Easy][Python][动态规划] Problem LeetCode You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n

回溯解决爬楼梯问题

1.问题描写叙述 每次爬楼梯有每次可跨1,2,3步.爬上一个N阶楼梯有多少种方式,打印出每种方式. 2.源码 // ConsoleApplication6.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include <vector> #include <map> using namespace std; typedef std::vector<int> V

爬楼梯问题

// 爬楼梯.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include<iostream>using namespace std; int main(){ int n; cin >> n; int a = 1, b = 1, k = 0; if (n == 1 || n == 0) {  cout<<1; } while (--n > 0) {  k = a + b;  b = a;  a = k; 

蒜头爬楼梯

1000ms 65536K 蒜头君自从春节回来以后,体重就像加了特技一样duang~duang~地暴增起来.于是小蒜头打算每天爬楼梯来燃烧体内的脂肪(咦?蒜怎么会有脂肪=.=).蒜头在爬楼梯的时候脑洞大开,因为蒜头腿短,爬楼梯的时候一次只能迈1级或2级台阶,它就想到了,假如一共有n级台阶的话,它一共有多少种方法能够爬到楼梯顶部呢? 聪明的你快来帮帮小蒜头吧~建议你使用动态规划求解哦,直接搜索是会超时的^o^ 输入格式: 第一行输入一个数n(n<=50),代表楼梯的级数. 输出格式: 第一行输出你

codevs——1742 爬楼梯

1742 爬楼梯 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 小明家外面有一个长长的楼梯,共N阶.小明的腿很长,一次能跨过一或两阶.有一天,他突发奇想,想求出从最低阶到最高阶共有几种爬楼梯的方案.你帮帮他吧! 输入描述 Input Description 一个整数N. 输出描述 Output Description 一个整数,为方案总数. 样例输入 Sample Input 5 样例输出 Sample Output 8

3:爬楼梯

描述:假设你正在爬楼梯,需要n步你才能到达顶部.但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部? 样例 比如n=3,1+1+1=1+2=2+1=3,共有3中不同的方法 返回 3 class Solution { public: /** * @param n: An integer * @return: An integer */ long climbStairs(int n) { // write your code here if(n==0) return 1; long  s

爬楼梯(LintCode)

爬楼梯 假设你正在爬楼梯,需要n步你才能到达顶部.但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部? 样例 比如n=3,1+1+1=1+2=2+1=3,共有3中不同的方法 返回 3 用递归又超时了..于是又换了DP,dp并不熟悉,于是又搞了好久. 首先向右是跳一格,向下是跳两格,dp[j]是到达(i,j)的不同的路径数,把每一行最左的剩余步数为0的点的路径数求和就是答案. 1 public class Solution { 2 /** 3 * @param n: An integer

水leetcode 爬楼梯

public class Solution { public int climbStairs(int n) { if(n==1) return 1; if(n==2) return 2; int pre=1; int cur=2; for(int i=3;i<=n;i++) { int tem=pre; pre=cur; cur=pre+tem; } return cur; // else return climbStairs(n-1)+climbStairs(n-2); }} 水leetcod