hiho week 145 register

Ended

Participants:748

Verdict:Accepted
Score:100 / 100
Submitted:2017-04-10 17:06:24

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdio>
#include <cstring>
int n,m,s,t;
int dp[1005][1005],a[1005];
void mmin(int&a,int b){if(b<a)a=b;}
void solve()
{
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=1;i<=n;++i)
        scanf("%d",a+i);
    memset(dp,0x3f,sizeof(dp));
    for(int j=0;j<=m&&j*s-s<=a[1];++j)
    {
        if(a[1]>=j*s)
            dp[1][j]=(a[1]-j*s)/t+!!((a[1]-j*s)%t);
        else dp[1][j]=0;
    }
    for(int i=2;i<=n;++i)
    {
        for(int j=0;j<=m&&j*s-s<=a[i];++j)
        {
            int cnt_t;
            if(a[i]>=j*s)
                cnt_t=(a[i]-j*s)/t+!!((a[i]-j*s)%t);
            else cnt_t=0;
            for(int _j=0;_j+j<=m;++_j)
                mmin(dp[i][_j+j],dp[i-1][_j]+cnt_t);
        }
    }
    for(int i=0;i<=m;++i)
        if(dp[n][i]+i<=m)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX