| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 773 人关注过本帖
标题: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
帖 子:1029
专家分: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
快速回复:Adding Ones, Twos, and Threes
数据加载中...
 
   



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

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