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

时间: 2024-08-03 05:08:07

玲珑学院 1050 - array的相关文章

玲珑学院 1128 咸鱼拷问

1128 - 咸鱼拷问 Time Limit:3s Memory Limit:128MByte Submissions:367Solved:112 DESCRIPTION 给你两个序列A,B.每个序列有N个元素,我们定义第i个位置的咸鱼值为min(A[i],A[i-1]-A[i-B[i]+1])*max(A[i],A[i-1]-.A[i-B[i]+1]).. 现在咸鱼王想知道所有的咸鱼值,于是抓住了你,让你回答这道题.你能回答他吗? INPUT 第一行包括一个整数N(1<=N<=1e5) 第二

玲珑学院 1127 咸鱼文章

1127 - 咸鱼文章 Time Limit:1s Memory Limit:128MByte Submissions:474Solved:196 DESCRIPTION elttiL moT nwod eht teerts sllac ruo god " ehT peek god " . piZ si a peehs god . tuB nehw moT seirt ot yas " peeS " , ti semoc tuo " peek "

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

1138 - 震惊,99%+的中国人都会算错的问题 Time Limit:4s Memory Limit:128MByte Submissions:310Solved:87 DESCRIPTION 众所周知zhu是一个大厨,zhu一直有自己独特的咸鱼制作技巧.tang是一个咸鱼供应商,他告诉zhu在他那里面有N 条咸鱼(标号从1到N)可以被用来制作.每条咸鱼都有一个咸鱼值Ki,初始时Ki都是0:zhu是一个特别的人,他又M个咸数(咸鱼数字),对于每个咸数x,他都会满足所有标号是x倍数的咸鱼的咸鱼

玲珑学院 1149 - Buildings

题意:给出N,k,长度为N的数列,问有多少个区间满足区间最大值-区间最小值<=k 思路:RMQ+二分 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N=2e5+10; 5 int a[N],b[N]; 6 int dp1[N][20],dp2[N][20]; 7 int n,k; 8 9 void init(){ 10 memset(dp2,127,sizeof(d

玲珑学院 1052 - See car

1052 - See car Time Limit:2s Memory Limit:64MByte Submissions:594Solved:227 DESCRIPTION You are the god of cars, standing at (a, b) point.There are some cars at point (xi,yi), . If lots of cars and you are in one line, you can only see the car that i

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

http://www.ifrog.cc/acm/problem/1028 题解处:http://www.ifrog.cc/acm/solution/4 #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <algorithm> using namespace std; typedef long long LL; const int N =

玲珑学院 1010 - Alarm

1010 - Alarm Time Limit:1s Memory Limit:128MByte DESCRIPTION Given a number sequence [3,7,22,45,116,...] . Please tell me the k -th number. INPUT A number T (T<100) indicates the number of the input cases. Then for each case there only is one integer

玲珑学院OJ 1023 - Magic boy Bi Luo with his excited math problem 树状数组暴力

分析:a^b+2(a&b)=a+b  so->a^(-b)+2(a&(-b))=a-b 然后树状数组分类讨论即可 链接:http://www.ifrog.cc/acm/problem/1023 吐槽:这个题本来是mod(2^40),明显要用快速乘啊,但是用了以后狂T,不用反而过了,不懂出题人 #include <iostream> #include <algorithm> #include <cmath> #include <vector&g

php二维数组自定义排序

PHP一维数组的排序可以用sort(),asort(),arsort()等函数,但是PHP二维数组的排序需要自定义. 以下函数是对一个给定的二维数组按照指定的键值进行排序,先看函数定义: function array_sort($arr,$keys,$type='asc'){ $keysvalue = $new_array = array(); foreach ($arr as $k=>$v){ $keysvalue[$k] = $v[$keys]; } if($type == 'asc'){