“玲珑杯”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(1≤n≤105)n(1≤n≤105).The next line contains nn numbers ai(1≤ai≤109)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
- “玲珑杯”ACM比赛 Round #4 E题
- “玲珑杯”ACM比赛 Round #4 E -- array(dp)
- 玲珑杯”ACM比赛 Round #4 E -- array【DP】
- “玲珑杯”ACM比赛 Round #4
- “玲珑杯”ACM比赛 Round #22 E【贪心】
- “玲珑杯”ACM比赛 Round #4 A -- chess play
- “玲珑杯”ACM比赛 Round #4 G -- See car
- 玲珑杯”ACM比赛 Round #4 G -- See car【Set】
- “玲珑杯”ACM比赛 Round #4 B Best couple
- 玲珑杯”ACM比赛 Round #5
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #11 " ---1097
- “玲珑杯”ACM比赛 Round #11 D
- “玲珑杯”ACM比赛 Round #11
- “玲珑杯”ACM比赛 Round #12【dp】
- “玲珑杯”ACM比赛 Round #13
- 玲珑杯”ACM比赛 Round #15
- 数据库:SQlite3的C接口相关函数
- Java断言:assert
- Android弹幕功能实现,模仿斗鱼直播的弹幕效果
- 4.一些关简单的键字.package,private,this
- Leetcode||14.Longest Common Prefix
- “玲珑杯”ACM比赛 Round #4 E题
- dht11模块的学习
- 嵌入式驱动编写-第一个驱动程序
- 文件属性分析
- 高低压为什么不能共地的一个解释
- 项目版本不同导致Eclipse报错问题——关于在JDK1.7环境中,运行JDK1.8环境下编写的项目。
- C语言模拟考|Proper Fraction
- Python的垃圾回收
- 平面上的邮局