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. zabbix常用命令

    1. 查看mysql 各数据库大小命令 "Database Size in MB" FROM information_schema.TABLES GROUP BY table_sc ...

  2. codeforces A. Fox and Box Accumulation 解题报告

    题目链接:http://codeforces.com/problemset/problem/388/A 题目意思:有 n 个 boxes,每个box 有相同的 size 和 weight,但是stre ...

  3. CodeForces669E:Little Artem and Time Machine(CDQ分治)(或者用map+树状数组优美地解决)

    Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of cour ...

  4. C++之虚函数与虚继承详解

    准备工作 1.VS2012使用命令行选项查看对象的内存布局 微软的Visual Studio提供给用户显示C++对象在内存中的布局的选项:/d1reportSingleClassLayout.使用方法 ...

  5. tyvj1940创世纪——贪心(基环树)

    题目:http://www.joyoi.cn/problem/tyvj-1940 基环树的样子,看了书上的讲解,准备写树上DP,然后挂了: #include<iostream> #incl ...

  6. shell函数(调用、返回值,返回值获取)

    Shell函数返回值,常用的两种方式:return,echo 1) return 语句shell函数的返回值,可以和其他语言的返回值一样,通过return语句返回.示例1: [devadmin@swa ...

  7. 20个jQuery分页插件和教程

    1.客户端的jQuery 分页插件jPages jPages 是一个客户端的分页插件,但提供很多特性例如自动翻页.键盘和滚动浏览,延迟显示以及完全可定制的导航面板. Read More Demo 2. ...

  8. Rikka with Sequence

    题意: 给一长度为n的序列,维护三个操作:区间开根,区间加,区间求和. 解法: 注意到本题关键在于区间开根: 对于一个数字,只要进行$O(loglogT)$次开根即会变为1. 考虑线段树,对于线段数上 ...

  9. python 之enumerate函数

    对于一个seq,得到: (0, seq[0]), (1, seq[1]), (2, seq[2]) list1 = ["这", "是", "一个&qu ...

  10. Markdown编写github README.md

    Markdown编写github README.md 一.在线编辑器StackEdit Markdown在线编辑器地址 中文:https://www.zybuluo.com/mdeditor 英文:h ...