zoukankan      html  css  js  c++  java
  • 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 = 100000 + 200;
    long long dp[maxn][70 + 10];
    long long a[maxn];
    int n, q, x, y;
    
    void init()
    {
        memset(dp, 0, sizeof dp);
        for (int i = n; i >= 1; i--)
            for (int j = 1; j <= 70; j++)
                dp[i][j] = dp[i + j][j] + a[i];
    }
    
    int main()
    {
        while (~scanf("%d", &n)){
            for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
            init();
            scanf("%d", &q);
            while (q--)
            {
                scanf("%d%d", &x, &y);
                if (y == 0) printf("%lld
    ", a[x]);
                else
                {
                    if (y <= 70) printf("%lld
    ", dp[x][y]);
                    else
                    {
                        long long ans = 0;
                        for (int i = x; i <= n; i = i + y) ans = ans + a[i];
                        printf("%lld
    ", ans);
                    }
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    信号
    test
    keil4打开keil5工程卡死问题
    day01
    SSH问题
    QT_day02
    QT_day01
    C++_day9am
    文件描述符与重定向
    C++_day8pm_多态
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5249507.html
Copyright © 2011-2022 走看看