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 ...
随机推荐
- 项目管理系列--好用的代码评审(Code Review)工具
1. Gerrit Gerrit is a web based code review system, facilitating online code reviews for projects us ...
- 【Bigdecimal】
---恢复内容开始--- 大位数除法的时候注意1/3问题:异常:[Exception in thread "main" java.lang.ArithmeticException: ...
- Java并发编程系列之二十八:CompletionService
CompletionService简介 CompletionService与ExecutorService类似都可以用来执行线程池的任务,ExecutorService继承了Executor接口,而C ...
- 微信小程序 三元运算 checked
预期效果: 根据用户性别,显示radio group,并将相应radio checked 代码如下: <view class="form-line"> <v ...
- Angular4 step by step.3
1.Routes 路由模块 import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angul ...
- django-admin管理后台高级自定义
django自带的admin后台管理系统,在很多网站中被称为django的杀手级的应用.那么django-admin的适用情形倒底有哪些呢,一般 来说对于大型的商业性的项目通常不用采用django-a ...
- java四大特性详解
Java的四大基础特性一.抽象 父类为子类提供一些属性和行为,子类根据业务需求实现具体的行为. 抽象类使用abstract进行修饰,子类要实现所有的父类抽象方法否则子类也是抽象类.二.封装 把对象的属 ...
- sql: Compare Tables
---使用 UNION.INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式 select * from BookInfoList --存在不同的 selec ...
- 【转】OkHttp使用进阶 译自OkHttp Github官方教程
作者:GavinCT 出处:http://www.cnblogs.com/ct2011/ 英文版原版地址 Recipes · square/okhttp Wiki 同步get 下载一个文件,打印他的响 ...
- Android 初识Retrofit
什么是 Retrofit ? Retrofit 是一套 RESTful 架构的 Android(Java) 客户端实现,基于注解,提供 JSON to POJO(Plain Ordinary Java ...