玲珑学院 1050 - array

Posted 十年换你一句好久不见

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了玲珑学院 1050 - array相关的知识,希望对你有一定的参考价值。

1050 - array

Time Limit:3s Memory Limit:64MByte

Submissions:494Solved:155

DESCRIPTION

2 array is an array, which looks like:
1,2,4,8,16,32,64......a1=1 ,a[i+1]/a[i]=2;

Give you a number array, and your mission is to get the number of subsequences ,which is 2 array, of it.
Note: 2 array is a finite array.

OUTPUT
one line - the number of subsequence which is 2 array.(the answer will % 109+7
)
SAMPLE INPUT
2
4
1 2 1 2
4
1 2 4 4
SAMPLE OUTPUT
5
4
求可以组成的比值为2,首项为1的等比数列的个数,首先,不是1并且是奇数的舍弃,普通偶数舍弃,非连续的舍弃
动态规划
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int dp[40],t,n,x,ans,pos;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&x);
            if(x==1) dp[0]++;
            else
            {
                pos=0;
                while(!(x%2))
                {
                    x>>=1;
                    pos++;
                }
                if(x==1 && dp[pos-1]) dp[pos]=(dp[pos]+dp[pos-1])%MOD;
            }
        }
        ans=0;
        for(int i=0;i<32;i++)
            ans=(ans+dp[i])%MOD;
        printf("%d\\n",ans);
    }
    return 0;
}

 

 

以上是关于玲珑学院 1050 - array的主要内容,如果未能解决你的问题,请参考以下文章

玲珑学院 1127 咸鱼文章

玲珑学院 1052 - See car

玲珑学院 1149 - Buildings

玲珑学院 1128 咸鱼拷问

玲珑学院 1138 - 震惊,99%+的中国人都会算错的问题

玲珑学院OJ 1028 - Bob and Alice are playing numbers 字典树,dp