玲珑学院 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;
}

 

 

转载于:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7220463.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值