zoukankan      html  css  js  c++  java
  • E. Sleeping Schedule

    E. Sleeping Schedule
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vova had a pretty weird sleeping schedule. There are hh hours in a day. Vova will sleep exactly nn times. The ii-th time he will sleep exactly after aiai hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is 00). Each time Vova sleeps exactly one day (in other words, hh hours).

    Vova thinks that the ii-th sleeping time is good if he starts to sleep between hours ll and rr inclusive.

    Vova can control himself and before the ii-th time can choose between two options: go to sleep after aiai hours or after ai1ai−1 hours.

    Your task is to say the maximum number of good sleeping times Vova can obtain if he acts optimally.

    Input

    The first line of the input contains four integers n,h,ln,h,l and rr (1n2000,3h2000,0lr<h1≤n≤2000,3≤h≤2000,0≤l≤r<h) — the number of times Vova goes to sleep, the number of hours in a day and the segment of the good sleeping time.

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (1ai<h1≤ai<h), where aiai is the number of hours after which Vova goes to sleep the ii-th time.

    Output

    Print one integer — the maximum number of good sleeping times Vova can obtain if he acts optimally.

    Example
    input
    Copy
    7 24 21 23
    16 17 14 20 20 11 22
    
    output
    Copy
    3
    
    Note

    The maximum number of good times in the example is 33.

    The story starts from t=0t=0. Then Vova goes to sleep after a11a1−1 hours, now the time is 1515. This time is not good. Then Vova goes to sleep after a21a2−1 hours, now the time is 15+16=715+16=7. This time is also not good. Then Vova goes to sleep after a3a3 hours, now the time is 7+14=217+14=21. This time is good. Then Vova goes to sleep after a41a4−1 hours, now the time is 21+19=1621+19=16. This time is not good. Then Vova goes to sleep after a5a5 hours, now the time is 16+20=1216+20=12. This time is not good. Then Vova goes to sleep after a6a6 hours, now the time is 12+11=2312+11=23. This time is good. Then Vova goes to sleep after a7a7 hours, now the time is 23+22=2123+22=21. This time is also good.

     

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    //#include <unordered_map>
    //#include <bits/stdc++.h>
    //#include <xfunctional>
    #define ll  long long
    #define PII  pair<int, int>
    using namespace std;
    int dir[5][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } ,{ 0,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979;
    const int mod = 1e9 + 7;
    const int maxn = 2005;
    //if(x<0 || x>=r || y<0 || y>=c)
    //1000000000000000000
     
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    int n, h, l, r;
    int check(int x)
    {
        return l <= x && x <= r;
    }
     
    int main() 
    {
        cin >> n >> h >> l >> r;
        vector<int> a(n+1);
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        vector<vector<int>> dp(maxn, vector<int>(h+1, INT_MIN));
        dp[0][0] = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 0; j <= h; j++)
            {
                dp[i][j] = max(dp[i-1][(j - a[i] + h) % h], dp[i-1][(j - a[i] + 1 + h) % h]) + check(j);
            }
        }
        int res = *max_element(dp[n].begin(), dp[n].end());
        cout << res << endl;
        return 0;
    }

     

  • 相关阅读:
    使用HttpClient短信网关接口实现手机号验证码注册
    Linux安装nginx、redis(在线安装)
    Linux安装Tomcat(本地安装)
    Linux搭建java运行环境(本地安装)
    Linux的安装注意事项
    Linux的Shell常用命令
    applicationContext.xml的复用(import resource)
    Redis解决Session共享问题(如果开启nginx,实现负载均衡)
    Redis缓存商品查询信息(SpringMVC)
    Spring整合Redis
  • 原文地址:https://www.cnblogs.com/dealer/p/12683135.html
Copyright © 2011-2022 走看看