HUST 1601 Shepherd
间隔小的时候dp预处理,大的时候暴力。。正确做法不会。。。
dp[i][j]表示以i为开头,间隔为j的和,递推:dp[i][j] = dp[i + j][j] + a[i]
测试数据中间隔可能是0......
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn = + ;
long long dp[maxn][ + ];
long long a[maxn];
int n, q, x, y; void init()
{
memset(dp, , sizeof dp);
for (int i = n; i >= ; i--)
for (int j = ; j <= ; j++)
dp[i][j] = dp[i + j][j] + a[i];
} int main()
{
while (~scanf("%d", &n)){
for (int i = ; i <= n; i++) scanf("%lld", &a[i]);
init();
scanf("%d", &q);
while (q--)
{
scanf("%d%d", &x, &y);
if (y == ) printf("%lld\n", a[x]);
else
{
if (y <= ) printf("%lld\n", dp[x][y]);
else
{
long long ans = ;
for (int i = x; i <= n; i = i + y) ans = ans + a[i];
printf("%lld\n", ans);
}
}
}
}
return ;
}
HUST 1601 Shepherd的更多相关文章
- HUSTM 1601 - Shepherd
题目描述 Hehe keeps a flock of sheep, numbered from 1 to n and each with a weight wi. To keep the sheep ...
- HUST 1017 - Exact cover (Dancing Links 模板题)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...
- Shepherd – 在应用程序中轻松实现引导功能
Shepherd 是一个指导用户使用应用程序的 JavaScript 库.它使用 Tether——另一个开源库,实现所有的步骤.Tether 确保你的步骤不会溢出屏幕或被剪裁.你可以很容易地指导用户使 ...
- ubuntu 16.04 source (HUST and 163)
#HUST deb http://mirrors.hust.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://m ...
- Dancing Link --- 模板题 HUST 1017 - Exact cover
1017 - Exact cover Problem's Link: http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...
- 【BZOJ】1601: [Usaco2008 Oct]灌水(kruskal)
http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小 ...
- hust 1010 最短循环节点
题目链接:http://acm.hust.edu.cn/problem/show/1010 KMP失配指针的利用: next数组前缀和后缀最长公共长度,这样len - next[len];就是最短的循 ...
- 【HDOJ】1601 Galactic Import
Dijkstra. /* 1601 */ #include <cstdio> #include <cstring> #include <cstdlib> #defi ...
- webservice取文件修改时间,返回1601/1/1 8:00:00
若文件查找不到,则会返回1601/1/1 8:00:00,若能正确查找到该文件,则返回正确的修改时间.
随机推荐
- UVA - 1347 Tour(DP + 双调旅行商问题)
题意:给出按照x坐标排序的n个点,让我们求出从最左端点到最右短点然后再回来,并且经过所有点且只经过一次的最短路径. 分析:这个题目刘汝佳的算法书上也有详解(就在基础dp那一段),具体思路如下:按照题目 ...
- L9,a cold welcome
expression: a large crowd of 一大群 in twenty minutes’time 20分钟之后 一些时间使用的介词 in two year‘s time on Satur ...
- Spring注解基本解读
在一个类中使用Spring对象,办法如下: 使用注解的形式注入 从ApplicationContext中获取. T t = new ApplicationContext.getBean("x ...
- jQuery validation
之前做客户端验证感觉自己javascript 不行,虽然能写出来一完整的验证,但从不自信,一直觉得客户端验证是比较繁琐的事情,但是又不能不做,只到最开始接触ajax ,遇到了一个jQuery vali ...
- [转] Spring Security(01)——初体验
[转自:http://haohaoxuexi.iteye.com/blog/2154299] 首先我们为Spring Security专门建立一个Spring的配置文件,该文件就专门用来作为Sprin ...
- struts2语法--error页面如何捕获?
如果地址栏输入了不带后缀或者action为后缀, 不存在的页面跳转到error.jsp: struts.xml配置" <package name="default" ...
- English--Computer System
A: Hey, Bill, Can you tell what's wrong with my computer? I can't move the mouse, I can's user the k ...
- docker rmi all
docker stop $(docker ps -a -q) docker rm $(docker ps -a -q)
- A Game
A Game 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a game. There is a ...
- 1084:XX开公司<回溯>
Description 2020年,xx开了一家拥有N个员工的大公司.每天,xx都要分配N项工作给他的员工,但是,由于能力的不同,每个人对处理相同工作所需要的时间有快有慢.众所周知,xx是一个非常重视 ...