“玲珑杯”ACM比赛 Round #4 E -- array DP
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的更多相关文章
- “玲珑杯”ACM比赛 Round #19题解&源码【A,规律,B,二分,C,牛顿迭代法,D,平衡树,E,概率dp】
A -- simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 SAMPLE INPUT ...
- “玲珑杯”ACM比赛 Round #12题解&源码
我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧! A ...
- “玲珑杯”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 ...
- “玲珑杯”ACM比赛 Round #18
“玲珑杯”ACM比赛 Round #18 Start Time:2017-07-15 12:00:00 End Time:2017-07-15 15:46:00 A -- 计算几何你瞎暴力 Time ...
- “玲珑杯”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 ...
- lonlifeOJ1152 “玲珑杯”ACM比赛 Round #19 概率DP
E -- Expected value of the expression DESCRIPTION You are given an expression: A0O1A1O2A2⋯OnAnA0O1A1 ...
- “玲珑杯”ACM比赛 Round #18 C -- 图论你先敲完模板(和题目一点关系都没有,dp)
题目链接:http://www.ifrog.cc/acm/problem/1146?contest=1020&no=2 题解:显然知道这是一道dp而且 dp[i]=min(dp[j]+2^(x ...
- “玲珑杯”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 官方题解: 代码如 ...
- “玲珑杯”ACM比赛 Round #18 A 前缀预处理 D dp
DESCRIPTION 今天HHHH 考完了期末考试,他在教学楼里闲逛,他看着教学楼里一间间的教室,于是开始思考: 如果从一个坐标为 (x1,y1,z1)(x1,y1,z1) 的教室走到(x2,y2, ...
随机推荐
- html5--5-7 绘制圆/弧
html5--5-7 绘制圆/弧 学习要点 掌握arc() 方法创建圆弧/曲线(用于创建圆或部分圆) 矩形的绘制方法 rect(x,y,w,h)创建一个矩形 strokeRect(x,y,w,hx,y ...
- C语言 写的 表达式求值。
有不对的地方还望指出来,让我改正.谢谢.存一个代码 #include<stdio.h> #include<stdlib.h> #include<string.h> ...
- 【C/C++】产生随机数
#include<iostream> #include<Ctime> #include<Cstdlib> using namespace std; //产生n个st ...
- smali语法积累记录
1.constructor 我们知道运行一个类的时候会先调用static方法中的内容,比如: static { System.loadLibrary("qihooTest"); } ...
- Junit单元测试类
/*package zxdc.web; import static org.junit.Assert.*; import java.io.IOException; import javax.servl ...
- bzoj 4589 Hard Nim —— FWT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4589 先手必败,是一开始所有石子的异或和为0: 生成函数 (xpri[1] + xpri[2 ...
- 3.sql中的向上递归和向下递归
1.向下递归 select * from table_name where 条件 connect by prior bmbm(本级关联条件)=sjbmbm(上级关联条件) start with bmb ...
- 使用 SourceTree 管理ios项目
SourceTree 是一个非常优秀的版本控制软件,他是一个客户端,方便我们去接入 GitHub .BitBucke 上面托管的代码. 声明(1——4是来自简书的非个人作品,仅仅保存资料学习使用) 一 ...
- GetModuleFileNameW
GetModuleFileNameW( HMODULE hModule, //模块句柄 或应用程序的实例句柄 若参数为NULL,则返回该应用程序全路径 __out_ecount(nSize) LPWS ...
- SpringMVC笔记- 不配置HandlerMapping
使用SpringMVC框架时发现有的配置了HandlerMapping,而有的没有,那么它们有什么区别呢?不配置能不能正常使用框架呢? 下面我们看一看不配置任何HandlerMapping时,框架会使 ...