我在跟进程序时遇到了麻烦 [英] I am having trouble in following program

查看:62
本文介绍了我在跟进程序时遇到了麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题如下 -

一个字符串只包含0和1;

给定n(字符串的长度)找到可以有多少个字符串排列其中字符串的每个主要长度传染性子序列的数量大于或等于1的数量。



我的方法 -

我遵循一个模式,使得n = 2的答案是3,对于n = 3,答案是4,n = 4答案= 6,n = 5答案= 9 ....

但我的答案是不正确的。

以下是我的c代码。



The question is as follow--
A string contains only 0's and 1's;
Given n(length of the string) find how many permutations of string are possible where every prime length contagious subsequence of the string has greater or equal number of 0's than number of 1's.

My approach--
I have followed a pattern such that for n=2 answer is 3,for n=3 the answer is 4,n=4 answer=6,n=5 answer=9....
But my answer is not correct.
Following is my c code.

#include <stdio.h>

int main()
{
    
    
    
        long int n,i;
        scanf("%ld",&n);
        if(n<3)
        {
           
         if(n=2)
            printf("3");
        }
        else
        {
        long int a[n];
        
        a[0]=3;
        for(i=1;i<n-1;i++)
        a[i]=a[i-1]+i;
        long int temp=a[n-2]%1000000007;
        printf("%ld",temp);
        }
        printf("\n");
   
    return 0;
}

推荐答案

你的逻辑看起来也很可疑。



重写你的代码!



写一个类似
的函数


your logic looks suspiciuos too.

Rewrite your code!

Write a function like

int runTheTest(int input)





并使用输出



and work with some sample data with output

这篇关于我在跟进程序时遇到了麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆