| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 762 人关注过本帖
标题:c语言程序代码分析
只看楼主 加入收藏
gaoyong1206
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-10-2
收藏
 问题点数:0 回复次数:0 
c语言程序代码分析
题目:
Problem DescriptionThere are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other words, either no girl in the queue or more than one girl stands side by side. The case n=4 (n is the number of children) is like
FFFF, FFFM, MFFF, FFMM, MFFM, MMFF, MMMM
Here F stands for a girl and M stands for a boy. The total number of queue satisfied the headmaster’s needs is 7. Can you make a program to find the total number of queue with n children?

InputThere are multiple cases in this problem and ended by the EOF. In each case, there is only one integer n means the number of children (1<=n<=1000)
 
OutputFor each test case, there is only one integer means the number of queue satisfied the headmaster’s needs.

Sample Input 1 2 3

Sample Output 1 2 4

我提交的程序

#include
int f[1001][1000];
void add(int m)
{
    int i;
    for(i=0;i<100;i++)
    {
        f[m][i]=0;
    }
    for(i=1;i<=f[m-1][0];i++)
    {
        f[m][i]+=f[m-1][i]+f[m-2][i]+f[m-4][i];
        f[m][i+1]=f[m][i]/10;
        f[m][i]%=10;
    }
    if(f[m][f[m-1][0]+1])
    {
        f[m][0]=f[m-1][0]+1;
    }
    else
    {
        f[m][0]=f[m-1][0];
    }
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int i;
        for(i=0;i<4;i++)
        {
            f[i][0]=1;
        }
        f[0][1]=1;
        f[1][1]=1;
        f[2][1]=2;
        f[3][1]=4;
        for(i=4;i<=n;i++)
        {
            add(i);
        }
        for(i=f[n][0];i>0;i--)
        {
            printf("%d",f[n][i]);
        }
        printf("\n");
    }
    return 0;
这个代码虽然ac了,但是看了好久还是不懂什么意思,大家帮我分析分析。
搜索更多相关主题的帖子: c语言程序 single prescribed children either 
2011-10-07 12:49
快速回复:c语言程序代码分析
数据加载中...
 
   



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

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