“玲珑杯”ACM比赛 Round #4 E题

来源:互联网 发布:c语言编写驱动程序 编辑:程序博客网 时间:2024/05/16 17:13

E -- array

Time Limit:3s Memory Limit:64MByte

Submissions:443Solved:130

DESCRIPTION

2 array is an array, which looks like:
1,2,4,8,16,32,64......1,2,4,8,16,32,64......
a1=1  | ai+1ai=2a1=1  | ai+1ai=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.

INPUT
There are multiple test cases.The first line is a number T (T 10T ≤10), which means the number of cases.For each case, two integer n(1n105)n(1≤n≤105).The next line contains nn numbers ai(1ai109)ai(1≤ai≤109)
OUTPUT
one line - the number of subsequence which is 2 array.(the answer will% 109+7% 109+7)
SAMPLE INPUT
2
4
1 2 1 2
4
1 2 4 4
SAMPLE OUTPUT
5
4
SOLUTION
“玲珑杯”ACM比赛 Round #4
记录一下1,2,4-------各自的个数---


代码:

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longint lp;LL a[60],b[100010];LL dp[60],mod;void ss(){    lp=0;    LL op=1;    while (op<10000000000)    {        a[lp++]=op;        op*=2;    }    return ;}void slove(){    int n;scanf("%d",&n);    for (int i=1;i<=n;i++)        scanf("%lld",&b[i]);    memset(dp,0,sizeof(dp));    LL s1,ans=0;    for (int i=1;i<=n;i++)    {        if (upper_bound(a,a+lp,b[i])-lower_bound(a,a+lp,b[i]))        {            int k=lower_bound(a,a+lp,b[i])-a;            if (k==0)            {                s1=1;            }            else                s1=dp[k-1];            ans=(ans+s1)%mod;            dp[k]=(dp[k]+s1)%mod;        }    }    printf("%lld\n",ans);}int main(){    mod=1000000007;    ss();    int t;scanf("%d",&t);    while (t--)        slove();    return 0;}




0 0
原创粉丝点击