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 ",ans); } return 0; }