编程介的小学生 2019-03-05 22:07 采纳率: 0.4%
浏览 211

寻找非递减的子序列的一个算法问题,采用C语言的技术实现的方式是?

Problem Description
How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3, ...., sn} ? For example, we assume that S = {1, 2, 3}, and you can find seven nondecreasing subsequences, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}.

Input
The input consists of multiple test cases. Each case begins with a line containing a positive integer n that is the length of the sequence S, the next line contains n integers {s1, s2, s3, ...., sn}, 1 <= n <= 100000, 0 <= si <= 2^31.

Output
For each test case, output one line containing the number of nondecreasing subsequences you can find from the sequence S, the answer should % 1000000007.

Sample Input
3
1 2 3

Sample Output
7

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-08 04:46
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    #include <stdio.h>
    int main(){
        int i,j,k,n,m,l,r;
        long long ans=0;
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d",&m);
            l=m;
            k=i;
            j=0;
            while(l>0){
                if((l&1)!=0){
                    if(j>=k)
                        break;
                    else{
                        ans+=ans;
                        ans%=1000000007;
                    }
                }
                l>>=1;
                j++;
            }
            printf("%lld\n",ans);
        }
        return 0;
    }
    
    评论

报告相同问题?