标题:Adding Ones, Twos, and Threes
只看楼主
心剑菩提
Rank: 1
等 级:新手上路
帖 子:249
专家分:0
注 册:2007-5-17
 问题点数:0 回复次数:3 
Adding Ones, Twos, and Threes
Description

Integer 4 can be expressed as a sum of 1s, 2s, and 3s in seven different ways as follows:
1+1+1+1, (1)
1+1+2, (2)
1+2+1, (3)
2+1+1, (4)
2+2, (5)
1+3, (6)
3+1. (7)
Write a program that determines the number of ways in which a given integer can be expressed as a sum of 1s, 2s, and 3s. You may assume that the integer is positive and less than 36.


Input

The input consists of T test cases. The number of test cases (T ) is given in the first line of the input file. Each test case consists of an integer written in a single line.

Output

Print exactly one line for each test case. The line should contain an integer representing the number of ways.

Sample Input


3
4
7
10


Sample Output


7
44
274


Source
搜索更多相关主题的帖子: Adding Ones Threes Twos 
2008-03-06 14:06
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
得分:0 
程序代码:
#include <stdio.h>

int main()
{
    static int f[37]={1};
    for(int i=1;i<37;i++){
        f[i]=f[i-1]+f[i-2]+f[i-3];
    }    
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",f[n]);
    }    
}

2008-03-06 16:21
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
得分:0 
lz你的代码在数据结构里面有,是老静提供得算法结合里面的.....你找找啊

学习需要安静。。海盗要重新来过。。
2008-03-06 16:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-202213-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.557151 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved