codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries
题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为止,求每次询问要转换的次数。
题解:纯暴力会TLE,所以在k为根号100000范围内dp打表
dp[i][j]表示初始p为i, k为j,需要转换几次可以大于n。
状态转移方程:dp[i][j] = dp[i+a[i]+j] + 1
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; const int N = 1e5+;
const int M = +; int dp[N][M];
int a[N];
int n, q; int main()
{
int i, j;
scanf("%d", &n);
for(i = ; i <= n; ++i) {
scanf("%d", &a[i]);
} memset(dp, , sizeof(dp));
for(i = n; i >= ; --i) {//dp , 打表
for(j = ; j <= M; ++j) {
if(i + a[i] + j > n) dp[i][j] = ;
else {
dp[i][j] = dp[i+a[i]+j][j] + ;
}
}
} scanf("%d", &q);
while(q--) {
int x, y;
scanf("%d%d", &x, &y);
if(y <= 320) printf("%d\n", dp[x][y]);
else {
int ans = ;
for(int p = x; p <= n; p += a[p]+y)
ans++;
printf("%d\n", ans);
}
}
return ;
}
codeforces 797 E. Array Queries【dp,暴力】的更多相关文章
- 【codeforces 797E】Array Queries
[题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问 ...
- Codeforces#86D Powerful array(分块暴力)
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...
- CodeForces 754C Vladik and chat (DP+暴力)
题意:给定n个人的m个对话,问能不能找一个方式使得满足,上下楼层人名不同,并且自己不提及自己. 析:首先预处理每一层能有多少个user可选,dp[i][j] 表示第 i 层是不是可以选第 j 个use ...
- CodeForces 402D Upgrading Array (数学+DP)
题意:给出一个数列,可以进行一种操作将某一个前缀除去他们的gcd,有一个函数f(x),f(1) = 0 , f(x) = f(x/p)+1,f(x) = f(x/p)-1(p是坏素数), 求 sum( ...
- CodeForces 446A DZY Loves Sequences (DP+暴力)
题意:给定一个序列,让你找出一个最长的序列,使得最多改其中的一个数,使其变成严格上升序列. 析:f[i] 表示以 i 结尾的最长上升长度,g[i] 表示以 i 为开始的最长上升长度,这两个很容易就求得 ...
- Codeforces 797E - Array Queries
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~
1100 - Again Array Queries ...
- lightoj Again Array Queries
1100 - Again Array Queries PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...
随机推荐
- Redis云端架构深入浅出
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯云数据库 TencentDB 发表于云+社区专栏 作者介绍:邹鹏,腾讯云数据库Redis产品负责人,多年数据库.网络安全研发经验. ...
- no jpeg in java.library.path;java.lang.NoClassDefFoundError: Could not initialize class sun.awt.image.codec.JPEGImageEncoderImpl
no jpeg in java.library.path;java.lang.NoClassDefFoundError: Could not initialize class sun.awt.imag ...
- 2017年12月14日 LinQ高级查&&Asp.net WebForm Asp.net MVC
LinQ的高级查询用法 开头:StartsWith()结尾:EndsWith()模糊:Contains() 个数:Count最大值:Max(r => r.price)最小值:Min(r => ...
- .net core 填坑记之—格式转换问题
最近在将项目从.net 迁移到.net core环境中,迁移完成后,发布于Windows平台上进行测试,所有功能均能正常运行. 为了项目能够在正式环境也能正常运行,提前进行Linux环境部署(Cent ...
- Git错误解决(windows版本下的Git Shell)
第一个问题:怎么也不能将自己本地仓库代码pull到GitHub网站上? git push origin master Warning: Permanently added 'github.com,19 ...
- unity3d之实现各种滑动效果
一. 点击滑动页面 新建了一个带mask的prefab,加上代码只需要将图片prefab.按钮prefab和所想添加的图片 拖进去会自动生成按钮,滑动速度可以随意调time,滑动效果用itween实现 ...
- rabbitMQ windows 安装 入门(转)
rabbitMQ windows 安装 入门 1.下载,其实erlang不装也是可以的 下载 rabbitMQ :http://www.rabbitmq.com/download.html,安装r ...
- vcfc之zk+postsql+keystore(cassandra)框架分析
vcfc框架总结: 1 一. bus和keystore是如何协调处理的,什么样的问题是处理不了的? 1. 如果在备重启的过程中,主处理了某个时间1,备机如果同步数据呢? 二 .数据可靠性和一致性分析 ...
- Effective C++ .05 一些不自动生成copy assigment操作的情况
主要讲了 1. 一般情况下编译器会为类创建默认的构造函数,拷贝构造函数和copy assignment函数 2. 执行默认的拷贝构造/copy assignment函数时,如果成员有自己的拷贝构造/c ...
- [ZOJ1015]:Fishing Net
题面 Vjudge Sol 给出一个n个点的无向图,询问是否为弦图 做法见上上上篇博客 # include <bits/stdc++.h> # define RG register # d ...