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,若能正确查找到该文件,则返回正确的修改时间.
随机推荐
- 最小点集覆盖=最大匹配<二分图>/证明
来源 最小点集覆盖==最大匹配. 首先,最小点集覆盖一定>=最大匹配,因为假设最大匹配为n,那么我们就得到了n条互不相邻的边,光覆盖这些边就要用到n个点. 现在我们来思考为什么最小点击覆盖一定& ...
- 在写一个iOS应用之前必须做的7件事
转载自:http://www.cocoachina.com/ios/20160316/15685.html 原文:https://medium.com/ios-os-x-development/7-t ...
- hdu 2544 最短路 (spfa)
最短路 Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- Python基础学习6---存储器
Python提供一个标准的模块,称为 pickle .使用它你可以在一个文件中储存任何Python对象,之后你又可以把它完整无缺地取出来.这被称为 持久地 储存对象.还有另一个模块称为 cPickle ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- 教你用CSS代码写出的各种形状图形
做网页设计时经常要用到各种形状的图形,对于规则的图形很简单,但是对于不规则的图形,一般我们都是用图片,今天就在这里教大家怎样用css代码写出各种规则不同的图形 1.正方形 #square {width ...
- XML 从基础到精通
1.简介 XML(可扩展标记语言)语言是一种数据交换标准,用于存储数据:关键词是标记: XML具有以下优点: (1) 方便的穿过防火墙,在不同的操作系统之间通信,跨语言,跨平台.数据共享非常方便.(J ...
- idx_rebuild_diff_idx_l.sql
1. set echo on feedback on set timing on set time on set pagesize 1000 set linesize 150 spool 02_do_ ...
- JS检测图片的大小
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < ...
- HDU 5171 GTY's birthday gift 矩阵快速幂
GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...