http://www.ifrog.cc/acm/problem/1050?contest=1006&no=4

DP[val]表示以val这个值结尾的等差数列有多少个

DP[val] += DP[val / 2];

数值很大,用map<int, int>DP即可。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 1e5 + ;
set<int>ss;
map<int, int>dp;
const int MOD = 1e9 + ;
void work() {
ss.clear();
dp.clear();
int n;
cin >> n;
for (int i = ; i <= n; ++i) {
int x;
cin >> x;
if (x == ) {
ss.insert(x);
dp[]++;
} else {
if (x & ) continue;
ss.insert(x);
dp[x] += dp[x / ];
dp[x] %= MOD;
}
}
int ans = ;
for (set<int> :: iterator it = ss.begin(); it != ss.end(); ++it) {
int t = *it;
if (t == ) {
ans += dp[t];
ans %= MOD;
} else {
if (t & ) continue;
ans += dp[t];
ans %= MOD;
}
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
IOS;
int t;
cin >> t;
while (t--) work();
return ;
}

“玲珑杯”ACM比赛 Round #4 E -- array DP的更多相关文章

  1. “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】

    A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...

  2. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  3. “玲珑杯”ACM比赛 Round #1

    Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public ...

  4. “玲珑杯”ACM比赛 Round #18

    “玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...

  5. “玲珑杯”ACM比赛 Round #19 B -- Buildings (RMQ + 二分)

    “玲珑杯”ACM比赛 Round #19 Start Time:2017-07-29 14:00:00 End Time:2017-07-29 16:30:00 Refresh Time:2017-0 ...

  6. lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP

    E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...

  7. “玲珑杯”ACM比赛 Round #18 C -- 图论你先敲完模板(和题目一点关系都没有,dp)

    题目链接:http://www.ifrog.cc/acm/problem/1146?contest=1020&no=2 题解:显然知道这是一道dp而且 dp[i]=min(dp[j]+2^(x ...

  8. “玲珑杯”ACM比赛 Round #18---图论你先敲完模板(DP+思维)

    题目链接 DESCRIPTION INPUT OUTPUT SAMPLE INPUT 2 3 2 3 5 7 3 10 3 5 7 SAMPLE OUTPUT 12 26 HINT 官方题解: 代码如 ...

  9. “玲珑杯”ACM比赛 Round #18 A 前缀预处理 D dp

    DESCRIPTION 今天HHHH 考完了期末考试,他在教学楼里闲逛,他看着教学楼里一间间的教室,于是开始思考: 如果从一个坐标为 (x1,y1,z1)(x1,y1,z1) 的教室走到(x2,y2, ...

随机推荐

  1. C++打印变量地址

    %p专门用来打印变量的以十六进制表示的地址: #include<iostream> using namespace std; int main() { ; printf("a的地 ...

  2. BZOJ 1621 [Usaco2008 Open]Roads Around The Farm分岔路口:分治 递归

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1621 题意: 约翰的N(1≤N≤1,000,000,000)只奶牛要出发去探索牧场四周的土 ...

  3. javabean学习

    javabean是一种可重复使用且跨平台的软件组件.他可以分为:客户界面组件(UI,user interface)和没有用户界面,主要负责处理事务(如,数据处理.操作数据库等)地javabean ja ...

  4. Git基本用法2

    二.比较内容 1.比较提交 - Git Diff 现在我们对项目做些修改: $ cd gitproject # 向README文件添加一行 $ echo "new line" &g ...

  5. BZOJ_5416_[Noi2018]冒泡排序_DP+组合数+树状数组

    BZOJ_5416_[Noi2018]冒泡排序_DP+组合数+树状数组 Description www.lydsy.com/JudgeOnline/upload/noi2018day1.pdf 好题. ...

  6. POJ3211(trie+01背包)

    Washing Clothes Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 9384   Accepted: 2997 ...

  7. Solr查询空值字段

    摘要: Solr的查询一般都是查找满足某个关键词的文档,偶然一个需求是查询Solr中某个字段不为空的数据.查询空值数据字符串类型 可以通过下面这种查询方式找到所有描述description为空的数据. ...

  8. Flutter实战视频-移动电商-59.购物车_计算商品价格和数量

    59.购物车_计算商品价格和数量 本节课主要是加上自动计算的功能 provide/cart.dart 在provide的类里面增加两个变量 cart_bottom.dart 三个组件因为我们都需要套一 ...

  9. Makefile研究(二)—— 完整可移植性模板

    转自:http://blog.csdn.net/jundic/article/details/17676461 一直想写一个很全很好移植的Makefile模板,我觉得一个完整makefile 应该包含 ...

  10. c# 调用 webservices (转载)

    .net 调用webservice 总结 最近做一个项目,由于是在别人框架里开发app,导致了很多限制,其中一个就是不能直接引用webservice . 我们都知道,调用webserivice 最简单 ...